@netlify/dev 4.2.1 → 4.3.0
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/dist/main.cjs +21 -12
- package/dist/main.d.cts +12 -5
- package/dist/main.d.ts +12 -5
- package/dist/main.js +21 -12
- package/package.json +6 -6
package/dist/main.cjs
CHANGED
|
@@ -319,7 +319,7 @@ var NetlifyDev = class {
|
|
|
319
319
|
#logger;
|
|
320
320
|
#projectRoot;
|
|
321
321
|
#redirectsHandler;
|
|
322
|
-
#
|
|
322
|
+
#serverAddress;
|
|
323
323
|
#siteID;
|
|
324
324
|
#staticHandler;
|
|
325
325
|
#staticHandlerAdditionalDirectories;
|
|
@@ -344,10 +344,19 @@ var NetlifyDev = class {
|
|
|
344
344
|
};
|
|
345
345
|
this.#functionsServePath = import_node_path2.default.join(projectRoot, ".netlify", "functions-serve");
|
|
346
346
|
this.#logger = options.logger ?? globalThis.console;
|
|
347
|
-
this.#
|
|
347
|
+
this.#serverAddress = options.serverAddress;
|
|
348
348
|
this.#projectRoot = projectRoot;
|
|
349
349
|
this.#staticHandlerAdditionalDirectories = options.staticFiles?.directories ?? [];
|
|
350
350
|
}
|
|
351
|
+
getServerAddress(requestServerAddress) {
|
|
352
|
+
if (requestServerAddress) {
|
|
353
|
+
return requestServerAddress;
|
|
354
|
+
}
|
|
355
|
+
if (typeof this.#serverAddress === "string") {
|
|
356
|
+
return this.#serverAddress;
|
|
357
|
+
}
|
|
358
|
+
throw new Error("Server address is not defined");
|
|
359
|
+
}
|
|
351
360
|
/**
|
|
352
361
|
* Runs a request through the Netlify request chain and returns a `Response`
|
|
353
362
|
* if there's a match. We must not disturb the incoming request unless we
|
|
@@ -362,16 +371,17 @@ var NetlifyDev = class {
|
|
|
362
371
|
* @returns
|
|
363
372
|
*/
|
|
364
373
|
async handleInEphemeralDirectory(readRequest, getWriteRequest, destPath, options = {}) {
|
|
374
|
+
const serverAddress = this.getServerAddress(options.serverAddress);
|
|
365
375
|
const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(readRequest);
|
|
366
376
|
if (edgeFunctionMatch) {
|
|
367
377
|
return {
|
|
368
|
-
response: await edgeFunctionMatch.handle(getWriteRequest()),
|
|
378
|
+
response: await edgeFunctionMatch.handle(getWriteRequest(), serverAddress),
|
|
369
379
|
type: "edge-function"
|
|
370
380
|
};
|
|
371
381
|
}
|
|
372
382
|
const imageMatch = this.#imageHandler?.match(readRequest);
|
|
373
383
|
if (imageMatch) {
|
|
374
|
-
const response = await imageMatch.handle();
|
|
384
|
+
const response = await imageMatch.handle(serverAddress);
|
|
375
385
|
return { response, type: "image" };
|
|
376
386
|
}
|
|
377
387
|
const functionMatch = await this.#functionsHandler?.match(readRequest, destPath);
|
|
@@ -391,7 +401,7 @@ var NetlifyDev = class {
|
|
|
391
401
|
const redirectRequest = new Request(redirectMatch.target);
|
|
392
402
|
const imageMatch2 = this.#imageHandler?.match(redirectRequest);
|
|
393
403
|
if (imageMatch2) {
|
|
394
|
-
const response2 = await imageMatch2.handle();
|
|
404
|
+
const response2 = await imageMatch2.handle(serverAddress);
|
|
395
405
|
return { response: response2, type: "image" };
|
|
396
406
|
}
|
|
397
407
|
const functionMatch2 = await this.#functionsHandler?.match(redirectRequest, destPath);
|
|
@@ -511,15 +521,16 @@ var NetlifyDev = class {
|
|
|
511
521
|
});
|
|
512
522
|
this.#cleanupJobs.push(() => runtime.stop());
|
|
513
523
|
let serverAddress;
|
|
514
|
-
if (typeof this.#
|
|
515
|
-
serverAddress = this.#
|
|
516
|
-
} else if (this.#features.edgeFunctions || this.#features.images) {
|
|
524
|
+
if (typeof this.#serverAddress === "string") {
|
|
525
|
+
serverAddress = this.#serverAddress;
|
|
526
|
+
} else if (this.#serverAddress !== null && (this.#features.edgeFunctions || this.#features.images)) {
|
|
517
527
|
const passthroughServer = new import_dev_utils.HTTPServer(async (req) => {
|
|
518
528
|
const res = await this.handle(req);
|
|
519
529
|
return res ?? new Response(null, { status: 404 });
|
|
520
530
|
});
|
|
521
531
|
this.#cleanupJobs.push(() => passthroughServer.stop());
|
|
522
532
|
serverAddress = await passthroughServer.start();
|
|
533
|
+
this.#serverAddress = serverAddress;
|
|
523
534
|
}
|
|
524
535
|
let envVariables = {};
|
|
525
536
|
if (this.#features.environmentVariables) {
|
|
@@ -531,7 +542,7 @@ var NetlifyDev = class {
|
|
|
531
542
|
siteID
|
|
532
543
|
});
|
|
533
544
|
}
|
|
534
|
-
if (this.#features.edgeFunctions
|
|
545
|
+
if (this.#features.edgeFunctions) {
|
|
535
546
|
const env = Object.entries(envVariables).reduce((acc, [key, variable]) => {
|
|
536
547
|
if (variable.usedSource === "account" || variable.usedSource === "addons" || variable.usedSource === "internal" || variable.usedSource === "ui" || variable.usedSource.startsWith(".env")) {
|
|
537
548
|
return {
|
|
@@ -547,7 +558,6 @@ var NetlifyDev = class {
|
|
|
547
558
|
env,
|
|
548
559
|
geolocation: import_dev_utils.mockLocation,
|
|
549
560
|
logger: this.#logger,
|
|
550
|
-
originServerAddress: serverAddress,
|
|
551
561
|
siteID,
|
|
552
562
|
siteName: config?.siteInfo.name
|
|
553
563
|
});
|
|
@@ -596,8 +606,7 @@ var NetlifyDev = class {
|
|
|
596
606
|
if (this.#features.images) {
|
|
597
607
|
this.#imageHandler = new import_images.ImageHandler({
|
|
598
608
|
imagesConfig: this.#config?.config.images,
|
|
599
|
-
logger: this.#logger
|
|
600
|
-
originServerAddress: serverAddress
|
|
609
|
+
logger: this.#logger
|
|
601
610
|
});
|
|
602
611
|
}
|
|
603
612
|
return {
|
package/dist/main.d.cts
CHANGED
|
@@ -59,11 +59,6 @@ interface Features {
|
|
|
59
59
|
redirects?: {
|
|
60
60
|
enabled?: boolean;
|
|
61
61
|
};
|
|
62
|
-
/**
|
|
63
|
-
* If your local development setup has its own HTTP server (e.g. Vite), set
|
|
64
|
-
* its address here.
|
|
65
|
-
*/
|
|
66
|
-
serverAddress?: string;
|
|
67
62
|
/**
|
|
68
63
|
* Configuration options for serving static files.
|
|
69
64
|
*/
|
|
@@ -81,6 +76,11 @@ interface NetlifyDevOptions extends Features {
|
|
|
81
76
|
apiToken?: string;
|
|
82
77
|
logger?: Logger;
|
|
83
78
|
projectRoot?: string;
|
|
79
|
+
/**
|
|
80
|
+
* If your local development setup has its own HTTP server (e.g. Vite), set
|
|
81
|
+
* its address here.
|
|
82
|
+
*/
|
|
83
|
+
serverAddress?: string | null;
|
|
84
84
|
}
|
|
85
85
|
interface HandleOptions {
|
|
86
86
|
/**
|
|
@@ -90,11 +90,18 @@ interface HandleOptions {
|
|
|
90
90
|
* {@link} https://docs.netlify.com/routing/headers/
|
|
91
91
|
*/
|
|
92
92
|
headersCollector?: HeadersCollector;
|
|
93
|
+
/**
|
|
94
|
+
* If your local development setup has its own HTTP server (e.g. Vite), you
|
|
95
|
+
* can supply its address here. It will override any value defined in the
|
|
96
|
+
* top-level `serverAddress` setting.
|
|
97
|
+
*/
|
|
98
|
+
serverAddress?: string;
|
|
93
99
|
}
|
|
94
100
|
type ResponseType = 'edge-function' | 'function' | 'image' | 'redirect' | 'static';
|
|
95
101
|
declare class NetlifyDev {
|
|
96
102
|
#private;
|
|
97
103
|
constructor(options: NetlifyDevOptions);
|
|
104
|
+
private getServerAddress;
|
|
98
105
|
/**
|
|
99
106
|
* Runs a request through the Netlify request chain and returns a `Response`
|
|
100
107
|
* if there's a match. We must not disturb the incoming request unless we
|
package/dist/main.d.ts
CHANGED
|
@@ -59,11 +59,6 @@ interface Features {
|
|
|
59
59
|
redirects?: {
|
|
60
60
|
enabled?: boolean;
|
|
61
61
|
};
|
|
62
|
-
/**
|
|
63
|
-
* If your local development setup has its own HTTP server (e.g. Vite), set
|
|
64
|
-
* its address here.
|
|
65
|
-
*/
|
|
66
|
-
serverAddress?: string;
|
|
67
62
|
/**
|
|
68
63
|
* Configuration options for serving static files.
|
|
69
64
|
*/
|
|
@@ -81,6 +76,11 @@ interface NetlifyDevOptions extends Features {
|
|
|
81
76
|
apiToken?: string;
|
|
82
77
|
logger?: Logger;
|
|
83
78
|
projectRoot?: string;
|
|
79
|
+
/**
|
|
80
|
+
* If your local development setup has its own HTTP server (e.g. Vite), set
|
|
81
|
+
* its address here.
|
|
82
|
+
*/
|
|
83
|
+
serverAddress?: string | null;
|
|
84
84
|
}
|
|
85
85
|
interface HandleOptions {
|
|
86
86
|
/**
|
|
@@ -90,11 +90,18 @@ interface HandleOptions {
|
|
|
90
90
|
* {@link} https://docs.netlify.com/routing/headers/
|
|
91
91
|
*/
|
|
92
92
|
headersCollector?: HeadersCollector;
|
|
93
|
+
/**
|
|
94
|
+
* If your local development setup has its own HTTP server (e.g. Vite), you
|
|
95
|
+
* can supply its address here. It will override any value defined in the
|
|
96
|
+
* top-level `serverAddress` setting.
|
|
97
|
+
*/
|
|
98
|
+
serverAddress?: string;
|
|
93
99
|
}
|
|
94
100
|
type ResponseType = 'edge-function' | 'function' | 'image' | 'redirect' | 'static';
|
|
95
101
|
declare class NetlifyDev {
|
|
96
102
|
#private;
|
|
97
103
|
constructor(options: NetlifyDevOptions);
|
|
104
|
+
private getServerAddress;
|
|
98
105
|
/**
|
|
99
106
|
* Runs a request through the Netlify request chain and returns a `Response`
|
|
100
107
|
* if there's a match. We must not disturb the incoming request unless we
|
package/dist/main.js
CHANGED
|
@@ -285,7 +285,7 @@ var NetlifyDev = class {
|
|
|
285
285
|
#logger;
|
|
286
286
|
#projectRoot;
|
|
287
287
|
#redirectsHandler;
|
|
288
|
-
#
|
|
288
|
+
#serverAddress;
|
|
289
289
|
#siteID;
|
|
290
290
|
#staticHandler;
|
|
291
291
|
#staticHandlerAdditionalDirectories;
|
|
@@ -310,10 +310,19 @@ var NetlifyDev = class {
|
|
|
310
310
|
};
|
|
311
311
|
this.#functionsServePath = path2.join(projectRoot, ".netlify", "functions-serve");
|
|
312
312
|
this.#logger = options.logger ?? globalThis.console;
|
|
313
|
-
this.#
|
|
313
|
+
this.#serverAddress = options.serverAddress;
|
|
314
314
|
this.#projectRoot = projectRoot;
|
|
315
315
|
this.#staticHandlerAdditionalDirectories = options.staticFiles?.directories ?? [];
|
|
316
316
|
}
|
|
317
|
+
getServerAddress(requestServerAddress) {
|
|
318
|
+
if (requestServerAddress) {
|
|
319
|
+
return requestServerAddress;
|
|
320
|
+
}
|
|
321
|
+
if (typeof this.#serverAddress === "string") {
|
|
322
|
+
return this.#serverAddress;
|
|
323
|
+
}
|
|
324
|
+
throw new Error("Server address is not defined");
|
|
325
|
+
}
|
|
317
326
|
/**
|
|
318
327
|
* Runs a request through the Netlify request chain and returns a `Response`
|
|
319
328
|
* if there's a match. We must not disturb the incoming request unless we
|
|
@@ -328,16 +337,17 @@ var NetlifyDev = class {
|
|
|
328
337
|
* @returns
|
|
329
338
|
*/
|
|
330
339
|
async handleInEphemeralDirectory(readRequest, getWriteRequest, destPath, options = {}) {
|
|
340
|
+
const serverAddress = this.getServerAddress(options.serverAddress);
|
|
331
341
|
const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(readRequest);
|
|
332
342
|
if (edgeFunctionMatch) {
|
|
333
343
|
return {
|
|
334
|
-
response: await edgeFunctionMatch.handle(getWriteRequest()),
|
|
344
|
+
response: await edgeFunctionMatch.handle(getWriteRequest(), serverAddress),
|
|
335
345
|
type: "edge-function"
|
|
336
346
|
};
|
|
337
347
|
}
|
|
338
348
|
const imageMatch = this.#imageHandler?.match(readRequest);
|
|
339
349
|
if (imageMatch) {
|
|
340
|
-
const response = await imageMatch.handle();
|
|
350
|
+
const response = await imageMatch.handle(serverAddress);
|
|
341
351
|
return { response, type: "image" };
|
|
342
352
|
}
|
|
343
353
|
const functionMatch = await this.#functionsHandler?.match(readRequest, destPath);
|
|
@@ -357,7 +367,7 @@ var NetlifyDev = class {
|
|
|
357
367
|
const redirectRequest = new Request(redirectMatch.target);
|
|
358
368
|
const imageMatch2 = this.#imageHandler?.match(redirectRequest);
|
|
359
369
|
if (imageMatch2) {
|
|
360
|
-
const response2 = await imageMatch2.handle();
|
|
370
|
+
const response2 = await imageMatch2.handle(serverAddress);
|
|
361
371
|
return { response: response2, type: "image" };
|
|
362
372
|
}
|
|
363
373
|
const functionMatch2 = await this.#functionsHandler?.match(redirectRequest, destPath);
|
|
@@ -477,15 +487,16 @@ var NetlifyDev = class {
|
|
|
477
487
|
});
|
|
478
488
|
this.#cleanupJobs.push(() => runtime.stop());
|
|
479
489
|
let serverAddress;
|
|
480
|
-
if (typeof this.#
|
|
481
|
-
serverAddress = this.#
|
|
482
|
-
} else if (this.#features.edgeFunctions || this.#features.images) {
|
|
490
|
+
if (typeof this.#serverAddress === "string") {
|
|
491
|
+
serverAddress = this.#serverAddress;
|
|
492
|
+
} else if (this.#serverAddress !== null && (this.#features.edgeFunctions || this.#features.images)) {
|
|
483
493
|
const passthroughServer = new HTTPServer(async (req) => {
|
|
484
494
|
const res = await this.handle(req);
|
|
485
495
|
return res ?? new Response(null, { status: 404 });
|
|
486
496
|
});
|
|
487
497
|
this.#cleanupJobs.push(() => passthroughServer.stop());
|
|
488
498
|
serverAddress = await passthroughServer.start();
|
|
499
|
+
this.#serverAddress = serverAddress;
|
|
489
500
|
}
|
|
490
501
|
let envVariables = {};
|
|
491
502
|
if (this.#features.environmentVariables) {
|
|
@@ -497,7 +508,7 @@ var NetlifyDev = class {
|
|
|
497
508
|
siteID
|
|
498
509
|
});
|
|
499
510
|
}
|
|
500
|
-
if (this.#features.edgeFunctions
|
|
511
|
+
if (this.#features.edgeFunctions) {
|
|
501
512
|
const env = Object.entries(envVariables).reduce((acc, [key, variable]) => {
|
|
502
513
|
if (variable.usedSource === "account" || variable.usedSource === "addons" || variable.usedSource === "internal" || variable.usedSource === "ui" || variable.usedSource.startsWith(".env")) {
|
|
503
514
|
return {
|
|
@@ -513,7 +524,6 @@ var NetlifyDev = class {
|
|
|
513
524
|
env,
|
|
514
525
|
geolocation: mockLocation,
|
|
515
526
|
logger: this.#logger,
|
|
516
|
-
originServerAddress: serverAddress,
|
|
517
527
|
siteID,
|
|
518
528
|
siteName: config?.siteInfo.name
|
|
519
529
|
});
|
|
@@ -562,8 +572,7 @@ var NetlifyDev = class {
|
|
|
562
572
|
if (this.#features.images) {
|
|
563
573
|
this.#imageHandler = new ImageHandler({
|
|
564
574
|
imagesConfig: this.#config?.config.images,
|
|
565
|
-
logger: this.#logger
|
|
566
|
-
originServerAddress: serverAddress
|
|
575
|
+
logger: this.#logger
|
|
567
576
|
});
|
|
568
577
|
}
|
|
569
578
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/dev",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"description": "Emulation of the Netlify environment for local development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -52,15 +52,15 @@
|
|
|
52
52
|
"vitest": "^3.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@netlify/blobs": "
|
|
55
|
+
"@netlify/blobs": "10.0.0",
|
|
56
56
|
"@netlify/config": "^23.0.10",
|
|
57
57
|
"@netlify/dev-utils": "3.2.0",
|
|
58
|
-
"@netlify/edge-functions": "2.
|
|
59
|
-
"@netlify/functions": "4.1.
|
|
58
|
+
"@netlify/edge-functions": "2.15.0",
|
|
59
|
+
"@netlify/functions": "4.1.5",
|
|
60
60
|
"@netlify/headers": "2.0.2",
|
|
61
|
-
"@netlify/images": "1.
|
|
61
|
+
"@netlify/images": "1.1.0",
|
|
62
62
|
"@netlify/redirects": "3.0.2",
|
|
63
|
-
"@netlify/runtime": "4.0.
|
|
63
|
+
"@netlify/runtime": "4.0.4",
|
|
64
64
|
"@netlify/static": "3.0.2",
|
|
65
65
|
"ulid": "^3.0.0"
|
|
66
66
|
}
|