@builder.io/ai-utils 0.25.0 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/codegen.d.ts +1 -0
- package/src/projects.d.ts +4 -0
- package/src/proxy.d.ts +28 -0
- package/src/proxy.js +56 -0
- package/src/proxy.spec.d.ts +1 -0
- package/src/proxy.spec.js +316 -0
package/package.json
CHANGED
package/src/codegen.d.ts
CHANGED
package/src/projects.d.ts
CHANGED
|
@@ -461,6 +461,10 @@ interface BranchSharedData {
|
|
|
461
461
|
/** Whether this branch is for a code review - affects enabled agents and tools */
|
|
462
462
|
type?: BranchType | null;
|
|
463
463
|
agentType?: AgentType | null;
|
|
464
|
+
/** ID of the last PR review — doubles as the vcpCodeGenEvents completion ID for feedback */
|
|
465
|
+
lastReviewId?: string | null;
|
|
466
|
+
/** Timestamp of the last PR review */
|
|
467
|
+
lastReviewAt?: number | null;
|
|
464
468
|
}
|
|
465
469
|
/**
|
|
466
470
|
* fields that are required in the new branch format, but optional in the legacy branch format.
|
package/src/proxy.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ProxyConfig {
|
|
2
|
+
devServerUrl: string | undefined;
|
|
3
|
+
proxyOrigin: string | undefined;
|
|
4
|
+
proxyDefaultOrigin: string | undefined;
|
|
5
|
+
proxyDestination: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes proxy configuration by inferring `proxyOrigin` and `proxyDefaultOrigin`
|
|
9
|
+
* from the `devServerUrl` when they aren't explicitly provided.
|
|
10
|
+
*
|
|
11
|
+
* For localhost dev servers, `proxyOrigin` becomes a wildcard port pattern
|
|
12
|
+
* (e.g. `http://localhost:*`) so that any local port is matched, while
|
|
13
|
+
* `proxyDefaultOrigin` is set to the exact origin for default routing.
|
|
14
|
+
*
|
|
15
|
+
* For non-localhost URLs, both are set to the exact origin.
|
|
16
|
+
*
|
|
17
|
+
* When `proxyOrigin` is already set (or derived) but `proxyDefaultOrigin` is not,
|
|
18
|
+
* the default is inferred from the origin — unless the origin looks like a
|
|
19
|
+
* glob/pattern (contains `*` or lacks an explicit protocol).
|
|
20
|
+
*
|
|
21
|
+
* `proxyDestination` is always passed through unchanged.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getProxyConfig({ devServerUrl, proxyOrigin, proxyDefaultOrigin, proxyDestination, }: ProxyConfig): {
|
|
24
|
+
proxyOrigin: string | undefined;
|
|
25
|
+
proxyDefaultOrigin: string | undefined;
|
|
26
|
+
proxyDestination: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
export declare function isLocalhost(hostname: string | URL): boolean;
|
package/src/proxy.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes proxy configuration by inferring `proxyOrigin` and `proxyDefaultOrigin`
|
|
3
|
+
* from the `devServerUrl` when they aren't explicitly provided.
|
|
4
|
+
*
|
|
5
|
+
* For localhost dev servers, `proxyOrigin` becomes a wildcard port pattern
|
|
6
|
+
* (e.g. `http://localhost:*`) so that any local port is matched, while
|
|
7
|
+
* `proxyDefaultOrigin` is set to the exact origin for default routing.
|
|
8
|
+
*
|
|
9
|
+
* For non-localhost URLs, both are set to the exact origin.
|
|
10
|
+
*
|
|
11
|
+
* When `proxyOrigin` is already set (or derived) but `proxyDefaultOrigin` is not,
|
|
12
|
+
* the default is inferred from the origin — unless the origin looks like a
|
|
13
|
+
* glob/pattern (contains `*` or lacks an explicit protocol).
|
|
14
|
+
*
|
|
15
|
+
* `proxyDestination` is always passed through unchanged.
|
|
16
|
+
*/
|
|
17
|
+
export function getProxyConfig({ devServerUrl, proxyOrigin, proxyDefaultOrigin, proxyDestination, }) {
|
|
18
|
+
let parsedUrl;
|
|
19
|
+
if (devServerUrl) {
|
|
20
|
+
try {
|
|
21
|
+
parsedUrl = new URL(devServerUrl);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) { }
|
|
24
|
+
}
|
|
25
|
+
if (!proxyOrigin && parsedUrl) {
|
|
26
|
+
if (isLocalhost(parsedUrl.hostname)) {
|
|
27
|
+
proxyOrigin = `${parsedUrl.protocol}//${parsedUrl.hostname}:*`;
|
|
28
|
+
proxyDefaultOrigin = parsedUrl.origin;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
proxyOrigin = parsedUrl.origin;
|
|
32
|
+
proxyDefaultOrigin = parsedUrl.origin;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!proxyDefaultOrigin && proxyOrigin) {
|
|
36
|
+
const isPattern = proxyOrigin.includes("*") ||
|
|
37
|
+
(!proxyOrigin.startsWith("https://") &&
|
|
38
|
+
!proxyOrigin.startsWith("http://"));
|
|
39
|
+
if (!isPattern) {
|
|
40
|
+
proxyDefaultOrigin = proxyOrigin;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
proxyOrigin,
|
|
45
|
+
proxyDefaultOrigin,
|
|
46
|
+
proxyDestination,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function isLocalhost(hostname) {
|
|
50
|
+
let bare = typeof hostname === "string" ? hostname : hostname.hostname;
|
|
51
|
+
bare = bare.replace(/^\[|\]$/g, "");
|
|
52
|
+
return (bare === "localhost" ||
|
|
53
|
+
bare === "127.0.0.1" ||
|
|
54
|
+
bare === "::1" ||
|
|
55
|
+
bare === "0.0.0.0");
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { getProxyConfig, isLocalhost } from "./proxy";
|
|
3
|
+
describe("getProxyConfig", () => {
|
|
4
|
+
describe("when all inputs are undefined", () => {
|
|
5
|
+
it("should return all undefined values", () => {
|
|
6
|
+
const result = getProxyConfig({
|
|
7
|
+
devServerUrl: undefined,
|
|
8
|
+
proxyOrigin: undefined,
|
|
9
|
+
proxyDefaultOrigin: undefined,
|
|
10
|
+
proxyDestination: undefined,
|
|
11
|
+
});
|
|
12
|
+
expect(result).toEqual({
|
|
13
|
+
proxyOrigin: undefined,
|
|
14
|
+
proxyDefaultOrigin: undefined,
|
|
15
|
+
proxyDestination: undefined,
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe("proxyDestination passthrough", () => {
|
|
20
|
+
it("should always return proxyDestination unchanged", () => {
|
|
21
|
+
const result = getProxyConfig({
|
|
22
|
+
devServerUrl: undefined,
|
|
23
|
+
proxyOrigin: undefined,
|
|
24
|
+
proxyDefaultOrigin: undefined,
|
|
25
|
+
proxyDestination: "https://api.example.com",
|
|
26
|
+
});
|
|
27
|
+
expect(result.proxyDestination).toBe("https://api.example.com");
|
|
28
|
+
});
|
|
29
|
+
it("should preserve proxyDestination alongside derived values", () => {
|
|
30
|
+
const result = getProxyConfig({
|
|
31
|
+
devServerUrl: "http://localhost:3000",
|
|
32
|
+
proxyOrigin: undefined,
|
|
33
|
+
proxyDefaultOrigin: undefined,
|
|
34
|
+
proxyDestination: "https://api.example.com",
|
|
35
|
+
});
|
|
36
|
+
expect(result.proxyDestination).toBe("https://api.example.com");
|
|
37
|
+
expect(result.proxyOrigin).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("deriving from localhost devServerUrl", () => {
|
|
41
|
+
it("should create a wildcard port pattern for localhost", () => {
|
|
42
|
+
const result = getProxyConfig({
|
|
43
|
+
devServerUrl: "http://localhost:3000",
|
|
44
|
+
proxyOrigin: undefined,
|
|
45
|
+
proxyDefaultOrigin: undefined,
|
|
46
|
+
proxyDestination: undefined,
|
|
47
|
+
});
|
|
48
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
49
|
+
expect(result.proxyDefaultOrigin).toBe("http://localhost:3000");
|
|
50
|
+
});
|
|
51
|
+
it("should create a wildcard port pattern for 127.0.0.1", () => {
|
|
52
|
+
const result = getProxyConfig({
|
|
53
|
+
devServerUrl: "http://127.0.0.1:8080",
|
|
54
|
+
proxyOrigin: undefined,
|
|
55
|
+
proxyDefaultOrigin: undefined,
|
|
56
|
+
proxyDestination: undefined,
|
|
57
|
+
});
|
|
58
|
+
expect(result.proxyOrigin).toBe("http://127.0.0.1:*");
|
|
59
|
+
expect(result.proxyDefaultOrigin).toBe("http://127.0.0.1:8080");
|
|
60
|
+
});
|
|
61
|
+
it("should create a wildcard port pattern for [::1] (IPv6 loopback)", () => {
|
|
62
|
+
const result = getProxyConfig({
|
|
63
|
+
devServerUrl: "http://[::1]:4200",
|
|
64
|
+
proxyOrigin: undefined,
|
|
65
|
+
proxyDefaultOrigin: undefined,
|
|
66
|
+
proxyDestination: undefined,
|
|
67
|
+
});
|
|
68
|
+
expect(result.proxyOrigin).toBe("http://[::1]:*");
|
|
69
|
+
expect(result.proxyDefaultOrigin).toBe("http://[::1]:4200");
|
|
70
|
+
});
|
|
71
|
+
it("should handle 0.0.0.0", () => {
|
|
72
|
+
const result = getProxyConfig({
|
|
73
|
+
devServerUrl: "http://0.0.0.0:5173",
|
|
74
|
+
proxyOrigin: undefined,
|
|
75
|
+
proxyDefaultOrigin: undefined,
|
|
76
|
+
proxyDestination: undefined,
|
|
77
|
+
});
|
|
78
|
+
expect(result.proxyOrigin).toBe("http://0.0.0.0:*");
|
|
79
|
+
expect(result.proxyDefaultOrigin).toBe("http://0.0.0.0:5173");
|
|
80
|
+
});
|
|
81
|
+
it("should handle https localhost", () => {
|
|
82
|
+
const result = getProxyConfig({
|
|
83
|
+
devServerUrl: "https://localhost:3443",
|
|
84
|
+
proxyOrigin: undefined,
|
|
85
|
+
proxyDefaultOrigin: undefined,
|
|
86
|
+
proxyDestination: undefined,
|
|
87
|
+
});
|
|
88
|
+
expect(result.proxyOrigin).toBe("https://localhost:*");
|
|
89
|
+
expect(result.proxyDefaultOrigin).toBe("https://localhost:3443");
|
|
90
|
+
});
|
|
91
|
+
it("should handle localhost without explicit port (default 80)", () => {
|
|
92
|
+
const result = getProxyConfig({
|
|
93
|
+
devServerUrl: "http://localhost",
|
|
94
|
+
proxyOrigin: undefined,
|
|
95
|
+
proxyDefaultOrigin: undefined,
|
|
96
|
+
proxyDestination: undefined,
|
|
97
|
+
});
|
|
98
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
99
|
+
expect(result.proxyDefaultOrigin).toBe("http://localhost");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("deriving from non-localhost devServerUrl", () => {
|
|
103
|
+
it("should use exact origin for remote URLs", () => {
|
|
104
|
+
const result = getProxyConfig({
|
|
105
|
+
devServerUrl: "https://dev.example.com:8080",
|
|
106
|
+
proxyOrigin: undefined,
|
|
107
|
+
proxyDefaultOrigin: undefined,
|
|
108
|
+
proxyDestination: undefined,
|
|
109
|
+
});
|
|
110
|
+
expect(result.proxyOrigin).toBe("https://dev.example.com:8080");
|
|
111
|
+
expect(result.proxyDefaultOrigin).toBe("https://dev.example.com:8080");
|
|
112
|
+
});
|
|
113
|
+
it("should use exact origin for remote URL without port", () => {
|
|
114
|
+
const result = getProxyConfig({
|
|
115
|
+
devServerUrl: "https://staging.myapp.io",
|
|
116
|
+
proxyOrigin: undefined,
|
|
117
|
+
proxyDefaultOrigin: undefined,
|
|
118
|
+
proxyDestination: undefined,
|
|
119
|
+
});
|
|
120
|
+
expect(result.proxyOrigin).toBe("https://staging.myapp.io");
|
|
121
|
+
expect(result.proxyDefaultOrigin).toBe("https://staging.myapp.io");
|
|
122
|
+
});
|
|
123
|
+
it("should strip path from the URL and only use origin", () => {
|
|
124
|
+
const result = getProxyConfig({
|
|
125
|
+
devServerUrl: "https://dev.example.com/some/path",
|
|
126
|
+
proxyOrigin: undefined,
|
|
127
|
+
proxyDefaultOrigin: undefined,
|
|
128
|
+
proxyDestination: undefined,
|
|
129
|
+
});
|
|
130
|
+
expect(result.proxyOrigin).toBe("https://dev.example.com");
|
|
131
|
+
expect(result.proxyDefaultOrigin).toBe("https://dev.example.com");
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe("invalid devServerUrl", () => {
|
|
135
|
+
it("should not derive anything from an invalid URL", () => {
|
|
136
|
+
const result = getProxyConfig({
|
|
137
|
+
devServerUrl: "not-a-url",
|
|
138
|
+
proxyOrigin: undefined,
|
|
139
|
+
proxyDefaultOrigin: undefined,
|
|
140
|
+
proxyDestination: undefined,
|
|
141
|
+
});
|
|
142
|
+
expect(result.proxyOrigin).toBeUndefined();
|
|
143
|
+
expect(result.proxyDefaultOrigin).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
it("should not derive anything from an empty string", () => {
|
|
146
|
+
const result = getProxyConfig({
|
|
147
|
+
devServerUrl: "",
|
|
148
|
+
proxyOrigin: undefined,
|
|
149
|
+
proxyDefaultOrigin: undefined,
|
|
150
|
+
proxyDestination: undefined,
|
|
151
|
+
});
|
|
152
|
+
expect(result.proxyOrigin).toBeUndefined();
|
|
153
|
+
expect(result.proxyDefaultOrigin).toBeUndefined();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe("proxyOrigin already provided", () => {
|
|
157
|
+
it("should not override proxyOrigin from devServerUrl", () => {
|
|
158
|
+
const result = getProxyConfig({
|
|
159
|
+
devServerUrl: "http://localhost:3000",
|
|
160
|
+
proxyOrigin: "https://custom.origin.com",
|
|
161
|
+
proxyDefaultOrigin: undefined,
|
|
162
|
+
proxyDestination: undefined,
|
|
163
|
+
});
|
|
164
|
+
expect(result.proxyOrigin).toBe("https://custom.origin.com");
|
|
165
|
+
});
|
|
166
|
+
it("should infer proxyDefaultOrigin from a non-pattern proxyOrigin", () => {
|
|
167
|
+
const result = getProxyConfig({
|
|
168
|
+
devServerUrl: undefined,
|
|
169
|
+
proxyOrigin: "https://custom.origin.com",
|
|
170
|
+
proxyDefaultOrigin: undefined,
|
|
171
|
+
proxyDestination: undefined,
|
|
172
|
+
});
|
|
173
|
+
expect(result.proxyDefaultOrigin).toBe("https://custom.origin.com");
|
|
174
|
+
});
|
|
175
|
+
it("should infer proxyDefaultOrigin from http:// proxyOrigin", () => {
|
|
176
|
+
const result = getProxyConfig({
|
|
177
|
+
devServerUrl: undefined,
|
|
178
|
+
proxyOrigin: "http://my-server.local:9090",
|
|
179
|
+
proxyDefaultOrigin: undefined,
|
|
180
|
+
proxyDestination: undefined,
|
|
181
|
+
});
|
|
182
|
+
expect(result.proxyDefaultOrigin).toBe("http://my-server.local:9090");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("pattern proxyOrigin (should not infer proxyDefaultOrigin)", () => {
|
|
186
|
+
it("should not set proxyDefaultOrigin when proxyOrigin contains a wildcard", () => {
|
|
187
|
+
const result = getProxyConfig({
|
|
188
|
+
devServerUrl: undefined,
|
|
189
|
+
proxyOrigin: "http://localhost:*",
|
|
190
|
+
proxyDefaultOrigin: undefined,
|
|
191
|
+
proxyDestination: undefined,
|
|
192
|
+
});
|
|
193
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
194
|
+
expect(result.proxyDefaultOrigin).toBeUndefined();
|
|
195
|
+
});
|
|
196
|
+
it("should not set proxyDefaultOrigin when proxyOrigin has no protocol", () => {
|
|
197
|
+
const result = getProxyConfig({
|
|
198
|
+
devServerUrl: undefined,
|
|
199
|
+
proxyOrigin: "localhost:3000",
|
|
200
|
+
proxyDefaultOrigin: undefined,
|
|
201
|
+
proxyDestination: undefined,
|
|
202
|
+
});
|
|
203
|
+
expect(result.proxyOrigin).toBe("localhost:3000");
|
|
204
|
+
expect(result.proxyDefaultOrigin).toBeUndefined();
|
|
205
|
+
});
|
|
206
|
+
it("should not set proxyDefaultOrigin for a bare domain pattern", () => {
|
|
207
|
+
const result = getProxyConfig({
|
|
208
|
+
devServerUrl: undefined,
|
|
209
|
+
proxyOrigin: "*.example.com",
|
|
210
|
+
proxyDefaultOrigin: undefined,
|
|
211
|
+
proxyDestination: undefined,
|
|
212
|
+
});
|
|
213
|
+
expect(result.proxyOrigin).toBe("*.example.com");
|
|
214
|
+
expect(result.proxyDefaultOrigin).toBeUndefined();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
describe("proxyDefaultOrigin already provided", () => {
|
|
218
|
+
it("should not override proxyDefaultOrigin when already set", () => {
|
|
219
|
+
const result = getProxyConfig({
|
|
220
|
+
devServerUrl: "http://localhost:3000",
|
|
221
|
+
proxyOrigin: undefined,
|
|
222
|
+
proxyDefaultOrigin: "http://localhost:4000",
|
|
223
|
+
proxyDestination: undefined,
|
|
224
|
+
});
|
|
225
|
+
// proxyOrigin is derived from devServerUrl since it was undefined,
|
|
226
|
+
// but proxyDefaultOrigin is overwritten by the localhost derivation path
|
|
227
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
228
|
+
// The localhost derivation path sets proxyDefaultOrigin to the parsed origin
|
|
229
|
+
expect(result.proxyDefaultOrigin).toBe("http://localhost:3000");
|
|
230
|
+
});
|
|
231
|
+
it("should keep proxyDefaultOrigin when proxyOrigin is also provided", () => {
|
|
232
|
+
const result = getProxyConfig({
|
|
233
|
+
devServerUrl: undefined,
|
|
234
|
+
proxyOrigin: "https://app.example.com",
|
|
235
|
+
proxyDefaultOrigin: "https://default.example.com",
|
|
236
|
+
proxyDestination: undefined,
|
|
237
|
+
});
|
|
238
|
+
expect(result.proxyOrigin).toBe("https://app.example.com");
|
|
239
|
+
expect(result.proxyDefaultOrigin).toBe("https://default.example.com");
|
|
240
|
+
});
|
|
241
|
+
it("should keep proxyDefaultOrigin even with a pattern proxyOrigin", () => {
|
|
242
|
+
const result = getProxyConfig({
|
|
243
|
+
devServerUrl: undefined,
|
|
244
|
+
proxyOrigin: "http://localhost:*",
|
|
245
|
+
proxyDefaultOrigin: "http://localhost:3000",
|
|
246
|
+
proxyDestination: undefined,
|
|
247
|
+
});
|
|
248
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
249
|
+
expect(result.proxyDefaultOrigin).toBe("http://localhost:3000");
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
describe("edge cases", () => {
|
|
253
|
+
it("should handle devServerUrl with query params and hash", () => {
|
|
254
|
+
const result = getProxyConfig({
|
|
255
|
+
devServerUrl: "http://localhost:3000?foo=bar#baz",
|
|
256
|
+
proxyOrigin: undefined,
|
|
257
|
+
proxyDefaultOrigin: undefined,
|
|
258
|
+
proxyDestination: undefined,
|
|
259
|
+
});
|
|
260
|
+
expect(result.proxyOrigin).toBe("http://localhost:*");
|
|
261
|
+
expect(result.proxyDefaultOrigin).toBe("http://localhost:3000");
|
|
262
|
+
});
|
|
263
|
+
it("should handle devServerUrl with trailing slash", () => {
|
|
264
|
+
const result = getProxyConfig({
|
|
265
|
+
devServerUrl: "https://dev.example.com/",
|
|
266
|
+
proxyOrigin: undefined,
|
|
267
|
+
proxyDefaultOrigin: undefined,
|
|
268
|
+
proxyDestination: undefined,
|
|
269
|
+
});
|
|
270
|
+
expect(result.proxyOrigin).toBe("https://dev.example.com");
|
|
271
|
+
expect(result.proxyDefaultOrigin).toBe("https://dev.example.com");
|
|
272
|
+
});
|
|
273
|
+
it("should not derive proxyOrigin when devServerUrl is provided but proxyOrigin is already set", () => {
|
|
274
|
+
const result = getProxyConfig({
|
|
275
|
+
devServerUrl: "http://localhost:3000",
|
|
276
|
+
proxyOrigin: "http://already-set.com",
|
|
277
|
+
proxyDefaultOrigin: undefined,
|
|
278
|
+
proxyDestination: undefined,
|
|
279
|
+
});
|
|
280
|
+
expect(result.proxyOrigin).toBe("http://already-set.com");
|
|
281
|
+
// Should infer proxyDefaultOrigin from the non-pattern proxyOrigin
|
|
282
|
+
expect(result.proxyDefaultOrigin).toBe("http://already-set.com");
|
|
283
|
+
});
|
|
284
|
+
it("should handle all values being pre-set (no-op)", () => {
|
|
285
|
+
const result = getProxyConfig({
|
|
286
|
+
devServerUrl: "http://localhost:3000",
|
|
287
|
+
proxyOrigin: "http://my-origin.com",
|
|
288
|
+
proxyDefaultOrigin: "http://my-default.com",
|
|
289
|
+
proxyDestination: "http://my-dest.com",
|
|
290
|
+
});
|
|
291
|
+
expect(result).toEqual({
|
|
292
|
+
proxyOrigin: "http://my-origin.com",
|
|
293
|
+
proxyDefaultOrigin: "http://my-default.com",
|
|
294
|
+
proxyDestination: "http://my-dest.com",
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe("isLocalhost", () => {
|
|
300
|
+
it.each([
|
|
301
|
+
["localhost", true],
|
|
302
|
+
["127.0.0.1", true],
|
|
303
|
+
["::1", true],
|
|
304
|
+
["[::1]", true],
|
|
305
|
+
["0.0.0.0", true],
|
|
306
|
+
["[127.0.0.1]", true],
|
|
307
|
+
["example.com", false],
|
|
308
|
+
["192.168.1.1", false],
|
|
309
|
+
["10.0.0.1", false],
|
|
310
|
+
["localhostx", false],
|
|
311
|
+
["[localhost]", true],
|
|
312
|
+
["", false],
|
|
313
|
+
])("isLocalhost(%s) should be %s", (hostname, expected) => {
|
|
314
|
+
expect(isLocalhost(hostname)).toBe(expected);
|
|
315
|
+
});
|
|
316
|
+
});
|