@netlify/plugin-nextjs 5.10.0 → 5.10.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/LICENSE +22 -0
- package/dist/build/advanced-api-routes.js +136 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +293 -11
- package/dist/build/content/server.js +219 -11
- package/dist/build/content/static.js +112 -15
- package/dist/build/functions/edge.js +540 -7
- package/dist/build/functions/server.js +130 -11
- package/dist/build/image-cdn.js +1599 -3
- package/dist/build/plugin-context.js +292 -6
- package/dist/build/verification.js +104 -9
- package/dist/esm-chunks/{package-F536DQ6H.js → package-7HACW4PO.js} +11 -10
- package/dist/index.js +19 -40
- package/dist/run/config.js +6 -7
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +93 -1713
- package/dist/run/handlers/request-context.cjs +10 -3
- package/dist/run/handlers/server.js +14 -34
- package/dist/run/handlers/tracer.cjs +17 -116
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +183 -10
- package/dist/run/next.cjs +10 -1625
- package/dist/run/revalidate.js +24 -3
- package/dist/run/{regional-blob-store.cjs → storage/regional-blob-store.cjs} +44 -8
- package/dist/run/storage/request-scoped-in-memory-cache.cjs +1475 -0
- package/dist/run/storage/storage.cjs +84 -0
- package/dist/shared/blob-types.cjs +37 -0
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
- package/dist/esm-chunks/chunk-DLBTTDNJ.js +0 -309
- package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
- package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
- package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
- package/dist/esm-chunks/chunk-K4RDUZYO.js +0 -609
- package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-VTKZZRGT.js +0 -132
- package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
- package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
- package/dist/esm-chunks/chunk-YMNWVS6T.js +0 -218
- package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
- package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
- package/dist/esm-chunks/next-7JK63CHT.js +0 -567
|
@@ -121,6 +121,14 @@ var init_internal = __esm({
|
|
|
121
121
|
init_internal();
|
|
122
122
|
|
|
123
123
|
// src/run/handlers/request-context.cts
|
|
124
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
125
|
+
var REQUEST_COUNTER_KEY = Symbol.for("nf-request-counter");
|
|
126
|
+
var extendedGlobalThis = globalThis;
|
|
127
|
+
function getFallbackRequestID() {
|
|
128
|
+
const requestNumber = extendedGlobalThis[REQUEST_COUNTER_KEY] ?? 0;
|
|
129
|
+
extendedGlobalThis[REQUEST_COUNTER_KEY] = requestNumber + 1;
|
|
130
|
+
return `#${requestNumber}`;
|
|
131
|
+
}
|
|
124
132
|
function createRequestContext(request, context) {
|
|
125
133
|
const backgroundWorkPromises = [];
|
|
126
134
|
const isDebugRequest = request?.headers.has("x-nf-debug-logging") || request?.headers.has("x-next-debug-logging");
|
|
@@ -142,16 +150,15 @@ function createRequestContext(request, context) {
|
|
|
142
150
|
get backgroundWorkPromise() {
|
|
143
151
|
return Promise.allSettled(backgroundWorkPromises);
|
|
144
152
|
},
|
|
145
|
-
logger
|
|
153
|
+
logger,
|
|
154
|
+
requestID: request?.headers.get("x-nf-request-id") ?? getFallbackRequestID()
|
|
146
155
|
};
|
|
147
156
|
}
|
|
148
|
-
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
149
157
|
var requestContextAsyncLocalStorage;
|
|
150
158
|
function getRequestContextAsyncLocalStorage() {
|
|
151
159
|
if (requestContextAsyncLocalStorage) {
|
|
152
160
|
return requestContextAsyncLocalStorage;
|
|
153
161
|
}
|
|
154
|
-
const extendedGlobalThis = globalThis;
|
|
155
162
|
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
156
163
|
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
157
164
|
}
|
|
@@ -4,27 +4,6 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
getTracer
|
|
9
|
-
} from "../../esm-chunks/chunk-WHUPSPWV.js";
|
|
10
|
-
import {
|
|
11
|
-
adjustDateHeader,
|
|
12
|
-
setCacheControlHeaders,
|
|
13
|
-
setCacheStatusHeader,
|
|
14
|
-
setCacheTagsHeaders,
|
|
15
|
-
setVaryHeaders
|
|
16
|
-
} from "../../esm-chunks/chunk-YMNWVS6T.js";
|
|
17
|
-
import "../../esm-chunks/chunk-K4RDUZYO.js";
|
|
18
|
-
import {
|
|
19
|
-
getLogger,
|
|
20
|
-
getRequestContext
|
|
21
|
-
} from "../../esm-chunks/chunk-SGXRYMYQ.js";
|
|
22
|
-
import {
|
|
23
|
-
nextResponseProxy
|
|
24
|
-
} from "../../esm-chunks/chunk-XS27YRA5.js";
|
|
25
|
-
import "../../esm-chunks/chunk-5QSXBV7L.js";
|
|
26
|
-
import "../../esm-chunks/chunk-GNGHTHMQ.js";
|
|
27
|
-
import "../../esm-chunks/chunk-TYCYFZ22.js";
|
|
28
7
|
import {
|
|
29
8
|
__commonJS,
|
|
30
9
|
__toESM
|
|
@@ -3111,19 +3090,21 @@ function toComputeResponse(res) {
|
|
|
3111
3090
|
return res.computeResponse;
|
|
3112
3091
|
}
|
|
3113
3092
|
|
|
3114
|
-
// src/run/handlers/wait-until.cts
|
|
3115
|
-
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
3116
|
-
function setupWaitUntil() {
|
|
3117
|
-
;
|
|
3118
|
-
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
3119
|
-
get() {
|
|
3120
|
-
return { waitUntil: getRequestContext()?.trackBackgroundWork };
|
|
3121
|
-
}
|
|
3122
|
-
};
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
3093
|
// src/run/handlers/server.ts
|
|
3126
|
-
|
|
3094
|
+
import {
|
|
3095
|
+
adjustDateHeader,
|
|
3096
|
+
setCacheControlHeaders,
|
|
3097
|
+
setCacheStatusHeader,
|
|
3098
|
+
setCacheTagsHeaders,
|
|
3099
|
+
setVaryHeaders
|
|
3100
|
+
} from "../headers.js";
|
|
3101
|
+
import { nextResponseProxy } from "../revalidate.js";
|
|
3102
|
+
import { setFetchBeforeNextPatchedIt } from "../storage/storage.cjs";
|
|
3103
|
+
import { getLogger } from "./request-context.cjs";
|
|
3104
|
+
import { getTracer } from "./tracer.cjs";
|
|
3105
|
+
import { setupWaitUntil } from "./wait-until.cjs";
|
|
3106
|
+
setFetchBeforeNextPatchedIt(globalThis.fetch);
|
|
3107
|
+
var nextImportPromise = import("../next.cjs");
|
|
3127
3108
|
setupWaitUntil();
|
|
3128
3109
|
var nextHandler;
|
|
3129
3110
|
var nextConfig;
|
|
@@ -3193,7 +3174,6 @@ var server_default = async (request, _context, topLevelSpan, requestContext) =>
|
|
|
3193
3174
|
headers: response.headers,
|
|
3194
3175
|
request,
|
|
3195
3176
|
span,
|
|
3196
|
-
tracer,
|
|
3197
3177
|
requestContext
|
|
3198
3178
|
});
|
|
3199
3179
|
}
|
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/run/handlers/tracer.cts
|
|
21
21
|
var tracer_exports = {};
|
|
22
22
|
__export(tracer_exports, {
|
|
23
|
-
getTracer: () => getTracer
|
|
23
|
+
getTracer: () => getTracer,
|
|
24
|
+
recordWarning: () => recordWarning
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(tracer_exports);
|
|
26
27
|
|
|
@@ -845,120 +846,8 @@ function handleFn(span, opts, fn) {
|
|
|
845
846
|
}
|
|
846
847
|
}
|
|
847
848
|
|
|
848
|
-
// src/run/handlers/request-context.cts
|
|
849
|
-
var import_node_async_hooks = require("node:async_hooks");
|
|
850
|
-
|
|
851
|
-
// node_modules/@netlify/functions/dist/chunk-C6P2IO65.mjs
|
|
852
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
853
|
-
var __esm = (fn, res) => function __init() {
|
|
854
|
-
return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
// node_modules/@netlify/functions/dist/chunk-ATZ7N7EG.mjs
|
|
858
|
-
var import_process = require("process");
|
|
859
|
-
var systemLogTag;
|
|
860
|
-
var serializeError;
|
|
861
|
-
var LogLevel;
|
|
862
|
-
var SystemLogger;
|
|
863
|
-
var systemLogger;
|
|
864
|
-
var init_system_logger = __esm({
|
|
865
|
-
"src/lib/system_logger.ts"() {
|
|
866
|
-
systemLogTag = "__nfSystemLog";
|
|
867
|
-
serializeError = (error) => {
|
|
868
|
-
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
869
|
-
return {
|
|
870
|
-
error: error.message,
|
|
871
|
-
error_cause: cause,
|
|
872
|
-
error_stack: error.stack
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
876
|
-
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
877
|
-
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
878
|
-
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
879
|
-
return LogLevel2;
|
|
880
|
-
})(LogLevel || {});
|
|
881
|
-
SystemLogger = class _SystemLogger {
|
|
882
|
-
fields;
|
|
883
|
-
logLevel;
|
|
884
|
-
constructor(fields = {}, logLevel = 2) {
|
|
885
|
-
this.fields = fields;
|
|
886
|
-
this.logLevel = logLevel;
|
|
887
|
-
}
|
|
888
|
-
doLog(logger, message) {
|
|
889
|
-
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
893
|
-
}
|
|
894
|
-
log(message) {
|
|
895
|
-
if (this.logLevel > 2) {
|
|
896
|
-
return;
|
|
897
|
-
}
|
|
898
|
-
this.doLog(console.log, message);
|
|
899
|
-
}
|
|
900
|
-
debug(message) {
|
|
901
|
-
if (this.logLevel > 1) {
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
this.doLog(console.debug, message);
|
|
905
|
-
}
|
|
906
|
-
error(message) {
|
|
907
|
-
if (this.logLevel > 3) {
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
this.doLog(console.error, message);
|
|
911
|
-
}
|
|
912
|
-
withLogLevel(level) {
|
|
913
|
-
return new _SystemLogger(this.fields, level);
|
|
914
|
-
}
|
|
915
|
-
withFields(fields) {
|
|
916
|
-
return new _SystemLogger(
|
|
917
|
-
{
|
|
918
|
-
...this.fields,
|
|
919
|
-
...fields
|
|
920
|
-
},
|
|
921
|
-
this.logLevel
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
withError(error) {
|
|
925
|
-
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
926
|
-
return this.withFields(fields);
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
systemLogger = new SystemLogger();
|
|
930
|
-
}
|
|
931
|
-
});
|
|
932
|
-
|
|
933
|
-
// node_modules/@netlify/functions/dist/chunk-7ANA32NV.mjs
|
|
934
|
-
var init_internal = __esm({
|
|
935
|
-
"src/internal.ts"() {
|
|
936
|
-
init_system_logger();
|
|
937
|
-
}
|
|
938
|
-
});
|
|
939
|
-
|
|
940
|
-
// node_modules/@netlify/functions/dist/internal.mjs
|
|
941
|
-
init_internal();
|
|
942
|
-
|
|
943
|
-
// src/run/handlers/request-context.cts
|
|
944
|
-
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
945
|
-
var requestContextAsyncLocalStorage;
|
|
946
|
-
function getRequestContextAsyncLocalStorage() {
|
|
947
|
-
if (requestContextAsyncLocalStorage) {
|
|
948
|
-
return requestContextAsyncLocalStorage;
|
|
949
|
-
}
|
|
950
|
-
const extendedGlobalThis = globalThis;
|
|
951
|
-
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
952
|
-
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
953
|
-
}
|
|
954
|
-
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
955
|
-
requestContextAsyncLocalStorage = storage;
|
|
956
|
-
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
957
|
-
return storage;
|
|
958
|
-
}
|
|
959
|
-
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
960
|
-
|
|
961
849
|
// src/run/handlers/tracer.cts
|
|
850
|
+
var import_request_context = require("./request-context.cjs");
|
|
962
851
|
var spanMeta = /* @__PURE__ */ new WeakMap();
|
|
963
852
|
var spanCounter = /* @__PURE__ */ new WeakMap();
|
|
964
853
|
function spanHook(span) {
|
|
@@ -967,7 +856,7 @@ function spanHook(span) {
|
|
|
967
856
|
originalEnd(endTime);
|
|
968
857
|
const meta = spanMeta.get(span);
|
|
969
858
|
if (meta) {
|
|
970
|
-
const requestContext = getRequestContext();
|
|
859
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
971
860
|
if (requestContext?.captureServerTiming) {
|
|
972
861
|
const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
|
|
973
862
|
const serverTiming = requestContext.serverTiming ?? "";
|
|
@@ -1009,7 +898,19 @@ function getTracer() {
|
|
|
1009
898
|
}
|
|
1010
899
|
return tracer;
|
|
1011
900
|
}
|
|
901
|
+
function recordWarning(warning, span) {
|
|
902
|
+
const spanToRecordWarningOn = span ?? trace.getActiveSpan();
|
|
903
|
+
if (!spanToRecordWarningOn) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
spanToRecordWarningOn.recordException(warning);
|
|
907
|
+
spanToRecordWarningOn.setAttributes({
|
|
908
|
+
severity: "alert",
|
|
909
|
+
warning: true
|
|
910
|
+
});
|
|
911
|
+
}
|
|
1012
912
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1013
913
|
0 && (module.exports = {
|
|
1014
|
-
getTracer
|
|
914
|
+
getTracer,
|
|
915
|
+
recordWarning
|
|
1015
916
|
});
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
getLogger
|
|
9
|
-
} from "../../esm-chunks/chunk-SGXRYMYQ.js";
|
|
10
7
|
import {
|
|
11
8
|
esm_exports,
|
|
12
9
|
init_esm
|
|
@@ -68866,9 +68863,10 @@ var import_resources = __toESM(require_src5(), 1);
|
|
|
68866
68863
|
var import_sdk_node = __toESM(require_src36(), 1);
|
|
68867
68864
|
var import_sdk_trace_node = __toESM(require_src20(), 1);
|
|
68868
68865
|
var import_semantic_conventions = __toESM(require_src(), 1);
|
|
68866
|
+
import { getLogger } from "./request-context.cjs";
|
|
68869
68867
|
var {
|
|
68870
68868
|
default: { version, name }
|
|
68871
|
-
} = await import("../../esm-chunks/package-
|
|
68869
|
+
} = await import("../../esm-chunks/package-7HACW4PO.js");
|
|
68872
68870
|
var sdk = new import_sdk_node.NodeSDK({
|
|
68873
68871
|
resource: new import_resources.Resource({
|
|
68874
68872
|
[import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
|
|
@@ -23,127 +23,13 @@ __export(wait_until_exports, {
|
|
|
23
23
|
setupWaitUntil: () => setupWaitUntil
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(wait_until_exports);
|
|
26
|
-
|
|
27
|
-
// src/run/handlers/request-context.cts
|
|
28
|
-
var import_node_async_hooks = require("node:async_hooks");
|
|
29
|
-
|
|
30
|
-
// node_modules/@netlify/functions/dist/chunk-C6P2IO65.mjs
|
|
31
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
32
|
-
var __esm = (fn, res) => function __init() {
|
|
33
|
-
return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// node_modules/@netlify/functions/dist/chunk-ATZ7N7EG.mjs
|
|
37
|
-
var import_process = require("process");
|
|
38
|
-
var systemLogTag;
|
|
39
|
-
var serializeError;
|
|
40
|
-
var LogLevel;
|
|
41
|
-
var SystemLogger;
|
|
42
|
-
var systemLogger;
|
|
43
|
-
var init_system_logger = __esm({
|
|
44
|
-
"src/lib/system_logger.ts"() {
|
|
45
|
-
systemLogTag = "__nfSystemLog";
|
|
46
|
-
serializeError = (error) => {
|
|
47
|
-
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
48
|
-
return {
|
|
49
|
-
error: error.message,
|
|
50
|
-
error_cause: cause,
|
|
51
|
-
error_stack: error.stack
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
55
|
-
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
56
|
-
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
57
|
-
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
58
|
-
return LogLevel2;
|
|
59
|
-
})(LogLevel || {});
|
|
60
|
-
SystemLogger = class _SystemLogger {
|
|
61
|
-
fields;
|
|
62
|
-
logLevel;
|
|
63
|
-
constructor(fields = {}, logLevel = 2) {
|
|
64
|
-
this.fields = fields;
|
|
65
|
-
this.logLevel = logLevel;
|
|
66
|
-
}
|
|
67
|
-
doLog(logger, message) {
|
|
68
|
-
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
72
|
-
}
|
|
73
|
-
log(message) {
|
|
74
|
-
if (this.logLevel > 2) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.doLog(console.log, message);
|
|
78
|
-
}
|
|
79
|
-
debug(message) {
|
|
80
|
-
if (this.logLevel > 1) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
this.doLog(console.debug, message);
|
|
84
|
-
}
|
|
85
|
-
error(message) {
|
|
86
|
-
if (this.logLevel > 3) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.doLog(console.error, message);
|
|
90
|
-
}
|
|
91
|
-
withLogLevel(level) {
|
|
92
|
-
return new _SystemLogger(this.fields, level);
|
|
93
|
-
}
|
|
94
|
-
withFields(fields) {
|
|
95
|
-
return new _SystemLogger(
|
|
96
|
-
{
|
|
97
|
-
...this.fields,
|
|
98
|
-
...fields
|
|
99
|
-
},
|
|
100
|
-
this.logLevel
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
withError(error) {
|
|
104
|
-
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
105
|
-
return this.withFields(fields);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
systemLogger = new SystemLogger();
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// node_modules/@netlify/functions/dist/chunk-7ANA32NV.mjs
|
|
113
|
-
var init_internal = __esm({
|
|
114
|
-
"src/internal.ts"() {
|
|
115
|
-
init_system_logger();
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// node_modules/@netlify/functions/dist/internal.mjs
|
|
120
|
-
init_internal();
|
|
121
|
-
|
|
122
|
-
// src/run/handlers/request-context.cts
|
|
123
|
-
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
124
|
-
var requestContextAsyncLocalStorage;
|
|
125
|
-
function getRequestContextAsyncLocalStorage() {
|
|
126
|
-
if (requestContextAsyncLocalStorage) {
|
|
127
|
-
return requestContextAsyncLocalStorage;
|
|
128
|
-
}
|
|
129
|
-
const extendedGlobalThis = globalThis;
|
|
130
|
-
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
131
|
-
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
132
|
-
}
|
|
133
|
-
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
134
|
-
requestContextAsyncLocalStorage = storage;
|
|
135
|
-
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
136
|
-
return storage;
|
|
137
|
-
}
|
|
138
|
-
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
139
|
-
|
|
140
|
-
// src/run/handlers/wait-until.cts
|
|
26
|
+
var import_request_context = require("./request-context.cjs");
|
|
141
27
|
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
142
28
|
function setupWaitUntil() {
|
|
143
29
|
;
|
|
144
30
|
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
145
31
|
get() {
|
|
146
|
-
return { waitUntil: getRequestContext()?.trackBackgroundWork };
|
|
32
|
+
return { waitUntil: (0, import_request_context.getRequestContext)()?.trackBackgroundWork };
|
|
147
33
|
}
|
|
148
34
|
};
|
|
149
35
|
}
|
package/dist/run/headers.js
CHANGED
|
@@ -4,17 +4,190 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
adjustDateHeader,
|
|
9
|
-
setCacheControlHeaders,
|
|
10
|
-
setCacheStatusHeader,
|
|
11
|
-
setCacheTagsHeaders,
|
|
12
|
-
setVaryHeaders
|
|
13
|
-
} from "../esm-chunks/chunk-YMNWVS6T.js";
|
|
14
|
-
import "../esm-chunks/chunk-K4RDUZYO.js";
|
|
15
|
-
import "../esm-chunks/chunk-SGXRYMYQ.js";
|
|
16
|
-
import "../esm-chunks/chunk-TYCYFZ22.js";
|
|
17
7
|
import "../esm-chunks/chunk-OEQOKJGE.js";
|
|
8
|
+
|
|
9
|
+
// src/run/headers.ts
|
|
10
|
+
import { getLogger } from "./handlers/request-context.cjs";
|
|
11
|
+
import { recordWarning } from "./handlers/tracer.cjs";
|
|
12
|
+
import { getMemoizedKeyValueStoreBackedByRegionalBlobStore } from "./storage/storage.cjs";
|
|
13
|
+
var ALL_VARIATIONS = Symbol.for("ALL_VARIATIONS");
|
|
14
|
+
var NetlifyVaryKeys = /* @__PURE__ */ new Set(["header", "language", "cookie", "query", "country"]);
|
|
15
|
+
var isNetlifyVaryKey = (key) => NetlifyVaryKeys.has(key);
|
|
16
|
+
var generateNetlifyVaryValues = ({
|
|
17
|
+
header,
|
|
18
|
+
language,
|
|
19
|
+
cookie,
|
|
20
|
+
query,
|
|
21
|
+
country
|
|
22
|
+
}) => {
|
|
23
|
+
const values = [];
|
|
24
|
+
if (query.length !== 0) {
|
|
25
|
+
if (query.includes(ALL_VARIATIONS)) {
|
|
26
|
+
values.push(`query`);
|
|
27
|
+
} else {
|
|
28
|
+
values.push(`query=${query.join(`|`)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (header.length !== 0) {
|
|
32
|
+
values.push(`header=${header.join(`|`)}`);
|
|
33
|
+
}
|
|
34
|
+
if (language.length !== 0) {
|
|
35
|
+
values.push(`language=${language.join(`|`)}`);
|
|
36
|
+
}
|
|
37
|
+
if (cookie.length !== 0) {
|
|
38
|
+
values.push(`cookie=${cookie.join(`|`)}`);
|
|
39
|
+
}
|
|
40
|
+
if (country.length !== 0) {
|
|
41
|
+
values.push(`country=${country.join(`|`)}`);
|
|
42
|
+
}
|
|
43
|
+
return values.join(",");
|
|
44
|
+
};
|
|
45
|
+
var getHeaderValueArray = (header) => {
|
|
46
|
+
return header.split(",").map((value) => value.trim()).filter(Boolean);
|
|
47
|
+
};
|
|
48
|
+
var omitHeaderValues = (header, values) => {
|
|
49
|
+
const headerValues = getHeaderValueArray(header);
|
|
50
|
+
const filteredValues = headerValues.filter(
|
|
51
|
+
(value) => !values.some((val) => value.startsWith(val))
|
|
52
|
+
);
|
|
53
|
+
return filteredValues.join(", ");
|
|
54
|
+
};
|
|
55
|
+
var setVaryHeaders = (headers, request, { basePath, i18n }) => {
|
|
56
|
+
const netlifyVaryValues = {
|
|
57
|
+
header: ["x-nextjs-data", "x-next-debug-logging"],
|
|
58
|
+
language: [],
|
|
59
|
+
cookie: ["__prerender_bypass", "__next_preview_data"],
|
|
60
|
+
query: ["__nextDataReq"],
|
|
61
|
+
country: []
|
|
62
|
+
};
|
|
63
|
+
const vary = headers.get("vary");
|
|
64
|
+
if (vary !== null) {
|
|
65
|
+
netlifyVaryValues.header.push(...getHeaderValueArray(vary));
|
|
66
|
+
}
|
|
67
|
+
const path = new URL(request.url).pathname;
|
|
68
|
+
const locales = i18n && i18n.localeDetection !== false ? i18n.locales : [];
|
|
69
|
+
if (locales.length > 1 && (path === "/" || path === basePath)) {
|
|
70
|
+
netlifyVaryValues.language.push(...locales);
|
|
71
|
+
netlifyVaryValues.cookie.push(`NEXT_LOCALE`);
|
|
72
|
+
}
|
|
73
|
+
const userNetlifyVary = headers.get("netlify-vary");
|
|
74
|
+
if (userNetlifyVary) {
|
|
75
|
+
const directives = getHeaderValueArray(userNetlifyVary);
|
|
76
|
+
for (const directive of directives) {
|
|
77
|
+
const [key, value] = directive.split("=");
|
|
78
|
+
if (key === "query" && !value) {
|
|
79
|
+
netlifyVaryValues.query.push(ALL_VARIATIONS);
|
|
80
|
+
} else if (value && isNetlifyVaryKey(key)) {
|
|
81
|
+
netlifyVaryValues[key].push(...value.split("|"));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
headers.set(`netlify-vary`, generateNetlifyVaryValues(netlifyVaryValues));
|
|
86
|
+
};
|
|
87
|
+
var adjustDateHeader = async ({
|
|
88
|
+
headers,
|
|
89
|
+
request,
|
|
90
|
+
span,
|
|
91
|
+
requestContext
|
|
92
|
+
}) => {
|
|
93
|
+
const key = new URL(request.url).pathname;
|
|
94
|
+
let lastModified;
|
|
95
|
+
if (requestContext.responseCacheGetLastModified) {
|
|
96
|
+
lastModified = requestContext.responseCacheGetLastModified;
|
|
97
|
+
} else {
|
|
98
|
+
recordWarning(
|
|
99
|
+
new Error("lastModified not found in requestContext, falling back to trying blobs"),
|
|
100
|
+
span
|
|
101
|
+
);
|
|
102
|
+
const cacheStore = getMemoizedKeyValueStoreBackedByRegionalBlobStore({ consistency: "strong" });
|
|
103
|
+
const cacheEntry = await cacheStore.get(
|
|
104
|
+
key,
|
|
105
|
+
"get cache to calculate date header"
|
|
106
|
+
);
|
|
107
|
+
lastModified = cacheEntry?.lastModified;
|
|
108
|
+
}
|
|
109
|
+
if (!lastModified) {
|
|
110
|
+
recordWarning(
|
|
111
|
+
new Error(
|
|
112
|
+
"lastModified not found in either requestContext or blobs, date header for cached response is not set"
|
|
113
|
+
),
|
|
114
|
+
span
|
|
115
|
+
);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const lastModifiedDate = new Date(lastModified);
|
|
119
|
+
headers.set("x-nextjs-date", headers.get("date") ?? lastModifiedDate.toUTCString());
|
|
120
|
+
headers.set("date", lastModifiedDate.toUTCString());
|
|
121
|
+
};
|
|
122
|
+
function setCacheControlFromRequestContext(headers, revalidate) {
|
|
123
|
+
const cdnCacheControl = (
|
|
124
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
125
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${revalidate || 31536e3}, stale-while-revalidate=31536000, durable`
|
|
126
|
+
);
|
|
127
|
+
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
128
|
+
}
|
|
129
|
+
var setCacheControlHeaders = ({ headers, status }, request, requestContext, nextConfig) => {
|
|
130
|
+
if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
131
|
+
setCacheControlFromRequestContext(headers, requestContext.routeHandlerRevalidate);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (status === 308 && request.url.endsWith("/") !== nextConfig.trailingSlash) {
|
|
135
|
+
getLogger().withFields({ trailingSlash: nextConfig.trailingSlash, location: headers.get("location") }).log("NetlifyHeadersHandler.trailingSlashRedirect");
|
|
136
|
+
}
|
|
137
|
+
const cacheControl = headers.get("cache-control");
|
|
138
|
+
if (status === 404) {
|
|
139
|
+
if (request.url.endsWith(".php")) {
|
|
140
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
141
|
+
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (process.env.CACHE_404_PAGE && request.url.endsWith("/404") && ["GET", "HEAD"].includes(request.method)) {
|
|
145
|
+
setCacheControlFromRequestContext(headers, requestContext.pageHandlerRevalidate);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
150
|
+
const browserCacheControl = omitHeaderValues(cacheControl, [
|
|
151
|
+
"s-maxage",
|
|
152
|
+
"stale-while-revalidate"
|
|
153
|
+
]);
|
|
154
|
+
const cdnCacheControl = (
|
|
155
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
156
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
|
|
157
|
+
...getHeaderValueArray(cacheControl).map(
|
|
158
|
+
(value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
|
|
159
|
+
),
|
|
160
|
+
"durable"
|
|
161
|
+
].join(", ")
|
|
162
|
+
);
|
|
163
|
+
headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
|
|
164
|
+
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (cacheControl === null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control") && requestContext.usedFsReadForNonFallback) {
|
|
168
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
169
|
+
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var setCacheTagsHeaders = (headers, requestContext) => {
|
|
173
|
+
if (requestContext.responseCacheTags && (headers.has("cache-control") || headers.has("netlify-cdn-cache-control"))) {
|
|
174
|
+
headers.set("netlify-cache-tag", requestContext.responseCacheTags.join(","));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var NEXT_CACHE_TO_CACHE_STATUS = {
|
|
178
|
+
HIT: `hit`,
|
|
179
|
+
MISS: `fwd=miss`,
|
|
180
|
+
STALE: `hit; fwd=stale`
|
|
181
|
+
};
|
|
182
|
+
var setCacheStatusHeader = (headers, nextCache) => {
|
|
183
|
+
if (typeof nextCache === "string") {
|
|
184
|
+
if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
|
|
185
|
+
const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
|
|
186
|
+
headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
|
|
187
|
+
}
|
|
188
|
+
headers.delete("x-nextjs-cache");
|
|
189
|
+
}
|
|
190
|
+
};
|
|
18
191
|
export {
|
|
19
192
|
adjustDateHeader,
|
|
20
193
|
setCacheControlHeaders,
|