@netlify/plugin-nextjs 5.10.0 → 5.10.1
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/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-UN6EVEHD.js} +1 -1
- package/dist/index.js +19 -40
- package/dist/run/config.js +1 -4
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +44 -1654
- package/dist/run/handlers/server.js +14 -33
- package/dist/run/handlers/tracer.cjs +2 -114
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +198 -10
- package/dist/run/next.cjs +11 -1623
- package/dist/run/regional-blob-store.cjs +37 -4
- package/dist/run/revalidate.js +24 -3
- 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
|
@@ -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 { setFetchBeforeNextPatchedIt } from "../regional-blob-store.cjs";
|
|
3102
|
+
import { nextResponseProxy } from "../revalidate.js";
|
|
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;
|
|
@@ -845,120 +845,8 @@ function handleFn(span, opts, fn) {
|
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
|
|
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
848
|
// src/run/handlers/tracer.cts
|
|
849
|
+
var import_request_context = require("./request-context.cjs");
|
|
962
850
|
var spanMeta = /* @__PURE__ */ new WeakMap();
|
|
963
851
|
var spanCounter = /* @__PURE__ */ new WeakMap();
|
|
964
852
|
function spanHook(span) {
|
|
@@ -967,7 +855,7 @@ function spanHook(span) {
|
|
|
967
855
|
originalEnd(endTime);
|
|
968
856
|
const meta = spanMeta.get(span);
|
|
969
857
|
if (meta) {
|
|
970
|
-
const requestContext = getRequestContext();
|
|
858
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
971
859
|
if (requestContext?.captureServerTiming) {
|
|
972
860
|
const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
|
|
973
861
|
const serverTiming = requestContext.serverTiming ?? "";
|
|
@@ -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-UN6EVEHD.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,205 @@
|
|
|
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 { encodeBlobKey } from "../shared/blobkey.js";
|
|
11
|
+
import { getLogger } from "./handlers/request-context.cjs";
|
|
12
|
+
import { getRegionalBlobStore } from "./regional-blob-store.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
|
+
tracer,
|
|
92
|
+
requestContext
|
|
93
|
+
}) => {
|
|
94
|
+
const key = new URL(request.url).pathname;
|
|
95
|
+
let lastModified;
|
|
96
|
+
if (requestContext.responseCacheGetLastModified) {
|
|
97
|
+
lastModified = requestContext.responseCacheGetLastModified;
|
|
98
|
+
} else {
|
|
99
|
+
span.recordException(
|
|
100
|
+
new Error("lastModified not found in requestContext, falling back to trying blobs")
|
|
101
|
+
);
|
|
102
|
+
span.setAttributes({
|
|
103
|
+
severity: "alert",
|
|
104
|
+
warning: true
|
|
105
|
+
});
|
|
106
|
+
const blobStore = getRegionalBlobStore({ consistency: "strong" });
|
|
107
|
+
const blobKey = await encodeBlobKey(key);
|
|
108
|
+
lastModified = await tracer.withActiveSpan(
|
|
109
|
+
"get cache to calculate date header",
|
|
110
|
+
async (getBlobForDateSpan) => {
|
|
111
|
+
getBlobForDateSpan.setAttributes({
|
|
112
|
+
key,
|
|
113
|
+
blobKey
|
|
114
|
+
});
|
|
115
|
+
const blob = await blobStore.get(blobKey, { type: "json" }) ?? {};
|
|
116
|
+
getBlobForDateSpan.addEvent(blob ? "Cache hit" : "Cache miss");
|
|
117
|
+
return blob.lastModified;
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (!lastModified) {
|
|
122
|
+
span.recordException(
|
|
123
|
+
new Error(
|
|
124
|
+
"lastModified not found in either requestContext or blobs, date header for cached response is not set"
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
span.setAttributes({
|
|
128
|
+
severity: "alert",
|
|
129
|
+
warning: true
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const lastModifiedDate = new Date(lastModified);
|
|
134
|
+
headers.set("x-nextjs-date", headers.get("date") ?? lastModifiedDate.toUTCString());
|
|
135
|
+
headers.set("date", lastModifiedDate.toUTCString());
|
|
136
|
+
};
|
|
137
|
+
function setCacheControlFromRequestContext(headers, revalidate) {
|
|
138
|
+
const cdnCacheControl = (
|
|
139
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
140
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${revalidate || 31536e3}, stale-while-revalidate=31536000, durable`
|
|
141
|
+
);
|
|
142
|
+
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
143
|
+
}
|
|
144
|
+
var setCacheControlHeaders = ({ headers, status }, request, requestContext, nextConfig) => {
|
|
145
|
+
if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
146
|
+
setCacheControlFromRequestContext(headers, requestContext.routeHandlerRevalidate);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (status === 308 && request.url.endsWith("/") !== nextConfig.trailingSlash) {
|
|
150
|
+
getLogger().withFields({ trailingSlash: nextConfig.trailingSlash, location: headers.get("location") }).log("NetlifyHeadersHandler.trailingSlashRedirect");
|
|
151
|
+
}
|
|
152
|
+
const cacheControl = headers.get("cache-control");
|
|
153
|
+
if (status === 404) {
|
|
154
|
+
if (request.url.endsWith(".php")) {
|
|
155
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
156
|
+
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (process.env.CACHE_404_PAGE && request.url.endsWith("/404") && ["GET", "HEAD"].includes(request.method)) {
|
|
160
|
+
setCacheControlFromRequestContext(headers, requestContext.pageHandlerRevalidate);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
165
|
+
const browserCacheControl = omitHeaderValues(cacheControl, [
|
|
166
|
+
"s-maxage",
|
|
167
|
+
"stale-while-revalidate"
|
|
168
|
+
]);
|
|
169
|
+
const cdnCacheControl = (
|
|
170
|
+
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
171
|
+
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
|
|
172
|
+
...getHeaderValueArray(cacheControl).map(
|
|
173
|
+
(value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
|
|
174
|
+
),
|
|
175
|
+
"durable"
|
|
176
|
+
].join(", ")
|
|
177
|
+
);
|
|
178
|
+
headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
|
|
179
|
+
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (cacheControl === null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control") && requestContext.usedFsReadForNonFallback) {
|
|
183
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
184
|
+
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
var setCacheTagsHeaders = (headers, requestContext) => {
|
|
188
|
+
if (requestContext.responseCacheTags && (headers.has("cache-control") || headers.has("netlify-cdn-cache-control"))) {
|
|
189
|
+
headers.set("netlify-cache-tag", requestContext.responseCacheTags.join(","));
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var NEXT_CACHE_TO_CACHE_STATUS = {
|
|
193
|
+
HIT: `hit`,
|
|
194
|
+
MISS: `fwd=miss`,
|
|
195
|
+
STALE: `hit; fwd=stale`
|
|
196
|
+
};
|
|
197
|
+
var setCacheStatusHeader = (headers, nextCache) => {
|
|
198
|
+
if (typeof nextCache === "string") {
|
|
199
|
+
if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
|
|
200
|
+
const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
|
|
201
|
+
headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
|
|
202
|
+
}
|
|
203
|
+
headers.delete("x-nextjs-cache");
|
|
204
|
+
}
|
|
205
|
+
};
|
|
18
206
|
export {
|
|
19
207
|
adjustDateHeader,
|
|
20
208
|
setCacheControlHeaders,
|