@netlify/plugin-nextjs 5.8.0 → 5.9.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/README.md +3 -2
- package/dist/build/advanced-api-routes.js +4 -136
- package/dist/build/cache.js +4 -25
- package/dist/build/content/prerendered.js +11 -272
- package/dist/build/content/server.js +11 -219
- package/dist/build/content/static.js +14 -97
- package/dist/build/functions/edge.js +7 -534
- package/dist/build/functions/server.js +11 -130
- package/dist/build/image-cdn.js +3 -1599
- package/dist/build/plugin-context.js +6 -266
- package/dist/build/templates/handler-monorepo.tmpl.js +1 -1
- package/dist/build/templates/handler.tmpl.js +1 -1
- package/dist/build/verification.js +9 -104
- package/dist/esm-chunks/chunk-72ZI2IVI.js +36 -0
- package/dist/esm-chunks/chunk-AMY4NOT5.js +1610 -0
- package/dist/esm-chunks/chunk-BEIUVQZK.js +212 -0
- package/dist/esm-chunks/chunk-BFYMHE3E.js +548 -0
- package/dist/esm-chunks/chunk-BVYZSEV6.js +306 -0
- package/dist/esm-chunks/chunk-DLVROEVU.js +144 -0
- package/dist/esm-chunks/chunk-GFYWJNQR.js +305 -0
- package/dist/esm-chunks/chunk-HWMLYAVP.js +122 -0
- package/dist/esm-chunks/chunk-IJZEDP6B.js +235 -0
- package/dist/esm-chunks/chunk-K4RDUZYO.js +609 -0
- package/dist/esm-chunks/chunk-KBX7SJLC.js +73 -0
- package/dist/esm-chunks/chunk-NDSDIXRD.js +122 -0
- package/dist/esm-chunks/chunk-TYCYFZ22.js +25 -0
- package/dist/esm-chunks/chunk-UYKENJEU.js +19 -0
- package/dist/esm-chunks/chunk-XS27YRA5.js +34 -0
- package/dist/esm-chunks/chunk-ZENB67PD.js +148 -0
- package/dist/esm-chunks/chunk-ZSVHJNNY.js +120 -0
- package/dist/esm-chunks/next-4L47PQSM.js +569 -0
- package/dist/esm-chunks/{package-4GFWM3PF.js → package-LCNINN36.js} +8 -7
- package/dist/index.js +39 -18
- package/dist/run/config.js +4 -1
- package/dist/run/constants.js +5 -7
- package/dist/run/handlers/cache.cjs +1618 -31
- package/dist/run/handlers/request-context.cjs +6 -2
- package/dist/run/handlers/server.js +40 -20
- package/dist/run/handlers/tracer.cjs +83 -2
- package/dist/run/handlers/tracing.js +4 -2
- package/dist/run/handlers/wait-until.cjs +122 -0
- package/dist/run/headers.js +9 -194
- package/dist/run/next.cjs +1604 -18
- package/dist/run/regional-blob-store.cjs +1 -1
- package/dist/run/revalidate.js +3 -24
- package/dist/shared/blobkey.js +3 -15
- package/package.json +4 -4
|
@@ -96,12 +96,16 @@ var SystemLogger = class _SystemLogger {
|
|
|
96
96
|
var systemLogger = new SystemLogger();
|
|
97
97
|
|
|
98
98
|
// src/run/handlers/request-context.cts
|
|
99
|
-
function createRequestContext(request) {
|
|
99
|
+
function createRequestContext(request, context) {
|
|
100
100
|
const backgroundWorkPromises = [];
|
|
101
101
|
return {
|
|
102
102
|
captureServerTiming: request?.headers.has("x-next-debug-logging") ?? false,
|
|
103
103
|
trackBackgroundWork: (promise) => {
|
|
104
|
-
|
|
104
|
+
if (context?.waitUntil) {
|
|
105
|
+
context.waitUntil(promise);
|
|
106
|
+
} else {
|
|
107
|
+
backgroundWorkPromises.push(promise);
|
|
108
|
+
}
|
|
105
109
|
},
|
|
106
110
|
get backgroundWorkPromise() {
|
|
107
111
|
return Promise.allSettled(backgroundWorkPromises);
|
|
@@ -4,6 +4,28 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
+
import {
|
|
8
|
+
getTracer
|
|
9
|
+
} from "../../esm-chunks/chunk-KBX7SJLC.js";
|
|
10
|
+
import {
|
|
11
|
+
createRequestContext,
|
|
12
|
+
getLogger,
|
|
13
|
+
getRequestContext
|
|
14
|
+
} from "../../esm-chunks/chunk-NDSDIXRD.js";
|
|
15
|
+
import {
|
|
16
|
+
adjustDateHeader,
|
|
17
|
+
setCacheControlHeaders,
|
|
18
|
+
setCacheStatusHeader,
|
|
19
|
+
setCacheTagsHeaders,
|
|
20
|
+
setVaryHeaders
|
|
21
|
+
} from "../../esm-chunks/chunk-BEIUVQZK.js";
|
|
22
|
+
import "../../esm-chunks/chunk-K4RDUZYO.js";
|
|
23
|
+
import {
|
|
24
|
+
nextResponseProxy
|
|
25
|
+
} from "../../esm-chunks/chunk-XS27YRA5.js";
|
|
26
|
+
import "../../esm-chunks/chunk-TYCYFZ22.js";
|
|
27
|
+
import "../../esm-chunks/chunk-5QSXBV7L.js";
|
|
28
|
+
import "../../esm-chunks/chunk-GNGHTHMQ.js";
|
|
7
29
|
import {
|
|
8
30
|
__commonJS,
|
|
9
31
|
__toESM
|
|
@@ -3090,18 +3112,20 @@ function toComputeResponse(res) {
|
|
|
3090
3112
|
return res.computeResponse;
|
|
3091
3113
|
}
|
|
3092
3114
|
|
|
3115
|
+
// src/run/handlers/wait-until.cts
|
|
3116
|
+
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
3117
|
+
function setupWaitUntil() {
|
|
3118
|
+
;
|
|
3119
|
+
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
3120
|
+
get() {
|
|
3121
|
+
return { waitUntil: getRequestContext()?.trackBackgroundWork };
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3093
3126
|
// src/run/handlers/server.ts
|
|
3094
|
-
import
|
|
3095
|
-
|
|
3096
|
-
setCacheControlHeaders,
|
|
3097
|
-
setCacheStatusHeader,
|
|
3098
|
-
setCacheTagsHeaders,
|
|
3099
|
-
setVaryHeaders
|
|
3100
|
-
} from "../headers.js";
|
|
3101
|
-
import { nextResponseProxy } from "../revalidate.js";
|
|
3102
|
-
import { createRequestContext, getLogger, getRequestContext } from "./request-context.cjs";
|
|
3103
|
-
import { getTracer } from "./tracer.cjs";
|
|
3104
|
-
var nextImportPromise = import("../next.cjs");
|
|
3127
|
+
var nextImportPromise = import("../../esm-chunks/next-4L47PQSM.js");
|
|
3128
|
+
setupWaitUntil();
|
|
3105
3129
|
var nextHandler;
|
|
3106
3130
|
var nextConfig;
|
|
3107
3131
|
var disableFaultyTransferEncodingHandling = (res) => {
|
|
@@ -3117,16 +3141,16 @@ var disableFaultyTransferEncodingHandling = (res) => {
|
|
|
3117
3141
|
return originalStoreHeader.call(this, firstLine, headers);
|
|
3118
3142
|
};
|
|
3119
3143
|
};
|
|
3120
|
-
var server_default = async (request
|
|
3144
|
+
var server_default = async (request) => {
|
|
3121
3145
|
const tracer = getTracer();
|
|
3122
3146
|
if (!nextHandler) {
|
|
3123
3147
|
await tracer.withActiveSpan("initialize next server", async () => {
|
|
3124
3148
|
const { getRunConfig, setRunConfig } = await import("../config.js");
|
|
3125
3149
|
nextConfig = await getRunConfig();
|
|
3126
3150
|
setRunConfig(nextConfig);
|
|
3127
|
-
const {
|
|
3151
|
+
const { getMockedRequestHandler } = await nextImportPromise;
|
|
3128
3152
|
const url = new URL(request.url);
|
|
3129
|
-
|
|
3153
|
+
nextHandler = await getMockedRequestHandler({
|
|
3130
3154
|
port: Number(url.port) || 443,
|
|
3131
3155
|
hostname: url.hostname,
|
|
3132
3156
|
dir: process.cwd(),
|
|
@@ -3169,15 +3193,11 @@ var server_default = async (request, context) => {
|
|
|
3169
3193
|
const body = await response.text();
|
|
3170
3194
|
return new Response(body || null, response);
|
|
3171
3195
|
}
|
|
3172
|
-
if (context.waitUntil) {
|
|
3173
|
-
context.waitUntil(requestContext.backgroundWorkPromise);
|
|
3174
|
-
}
|
|
3175
3196
|
const keepOpenUntilNextFullyRendered = new TransformStream({
|
|
3176
3197
|
async flush() {
|
|
3177
3198
|
await nextHandlerPromise;
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
}
|
|
3199
|
+
res.emit("close");
|
|
3200
|
+
await requestContext.backgroundWorkPromise;
|
|
3181
3201
|
}
|
|
3182
3202
|
});
|
|
3183
3203
|
return new Response(response.body?.pipeThrough(keepOpenUntilNextFullyRendered), response);
|
|
@@ -845,8 +845,89 @@ 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-HYMERDCV.mjs
|
|
852
|
+
var import_process = require("process");
|
|
853
|
+
var systemLogTag = "__nfSystemLog";
|
|
854
|
+
var serializeError = (error) => {
|
|
855
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
856
|
+
return {
|
|
857
|
+
error: error.message,
|
|
858
|
+
error_cause: cause,
|
|
859
|
+
error_stack: error.stack
|
|
860
|
+
};
|
|
861
|
+
};
|
|
862
|
+
var SystemLogger = class _SystemLogger {
|
|
863
|
+
fields;
|
|
864
|
+
logLevel;
|
|
865
|
+
constructor(fields = {}, logLevel = 2) {
|
|
866
|
+
this.fields = fields;
|
|
867
|
+
this.logLevel = logLevel;
|
|
868
|
+
}
|
|
869
|
+
doLog(logger, message) {
|
|
870
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
874
|
+
}
|
|
875
|
+
log(message) {
|
|
876
|
+
if (this.logLevel > 2) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
this.doLog(console.log, message);
|
|
880
|
+
}
|
|
881
|
+
debug(message) {
|
|
882
|
+
if (this.logLevel > 1) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
this.doLog(console.debug, message);
|
|
886
|
+
}
|
|
887
|
+
error(message) {
|
|
888
|
+
if (this.logLevel > 3) {
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
this.doLog(console.error, message);
|
|
892
|
+
}
|
|
893
|
+
withLogLevel(level) {
|
|
894
|
+
return new _SystemLogger(this.fields, level);
|
|
895
|
+
}
|
|
896
|
+
withFields(fields) {
|
|
897
|
+
return new _SystemLogger(
|
|
898
|
+
{
|
|
899
|
+
...this.fields,
|
|
900
|
+
...fields
|
|
901
|
+
},
|
|
902
|
+
this.logLevel
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
withError(error) {
|
|
906
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
907
|
+
return this.withFields(fields);
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
var systemLogger = new SystemLogger();
|
|
911
|
+
|
|
912
|
+
// src/run/handlers/request-context.cts
|
|
913
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
914
|
+
var requestContextAsyncLocalStorage;
|
|
915
|
+
function getRequestContextAsyncLocalStorage() {
|
|
916
|
+
if (requestContextAsyncLocalStorage) {
|
|
917
|
+
return requestContextAsyncLocalStorage;
|
|
918
|
+
}
|
|
919
|
+
const extendedGlobalThis = globalThis;
|
|
920
|
+
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
921
|
+
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
922
|
+
}
|
|
923
|
+
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
924
|
+
requestContextAsyncLocalStorage = storage;
|
|
925
|
+
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
926
|
+
return storage;
|
|
927
|
+
}
|
|
928
|
+
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
929
|
+
|
|
848
930
|
// src/run/handlers/tracer.cts
|
|
849
|
-
var import_request_context = require("./request-context.cjs");
|
|
850
931
|
var spanMeta = /* @__PURE__ */ new WeakMap();
|
|
851
932
|
var spanCounter = /* @__PURE__ */ new WeakMap();
|
|
852
933
|
function spanHook(span) {
|
|
@@ -855,7 +936,7 @@ function spanHook(span) {
|
|
|
855
936
|
originalEnd(endTime);
|
|
856
937
|
const meta = spanMeta.get(span);
|
|
857
938
|
if (meta) {
|
|
858
|
-
const requestContext =
|
|
939
|
+
const requestContext = getRequestContext();
|
|
859
940
|
if (requestContext?.captureServerTiming) {
|
|
860
941
|
const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
|
|
861
942
|
const serverTiming = requestContext.serverTiming ?? "";
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
+
import {
|
|
8
|
+
getLogger
|
|
9
|
+
} from "../../esm-chunks/chunk-NDSDIXRD.js";
|
|
7
10
|
import {
|
|
8
11
|
esm_exports,
|
|
9
12
|
init_esm
|
|
@@ -68863,10 +68866,9 @@ var import_resources = __toESM(require_src5(), 1);
|
|
|
68863
68866
|
var import_sdk_node = __toESM(require_src36(), 1);
|
|
68864
68867
|
var import_sdk_trace_node = __toESM(require_src20(), 1);
|
|
68865
68868
|
var import_semantic_conventions = __toESM(require_src(), 1);
|
|
68866
|
-
import { getLogger } from "./request-context.cjs";
|
|
68867
68869
|
var {
|
|
68868
68870
|
default: { version, name }
|
|
68869
|
-
} = await import("../../esm-chunks/package-
|
|
68871
|
+
} = await import("../../esm-chunks/package-LCNINN36.js");
|
|
68870
68872
|
var sdk = new import_sdk_node.NodeSDK({
|
|
68871
68873
|
resource: new import_resources.Resource({
|
|
68872
68874
|
[import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/run/handlers/wait-until.cts
|
|
21
|
+
var wait_until_exports = {};
|
|
22
|
+
__export(wait_until_exports, {
|
|
23
|
+
setupWaitUntil: () => setupWaitUntil
|
|
24
|
+
});
|
|
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-HYMERDCV.mjs
|
|
31
|
+
var import_process = require("process");
|
|
32
|
+
var systemLogTag = "__nfSystemLog";
|
|
33
|
+
var serializeError = (error) => {
|
|
34
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
35
|
+
return {
|
|
36
|
+
error: error.message,
|
|
37
|
+
error_cause: cause,
|
|
38
|
+
error_stack: error.stack
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
var SystemLogger = class _SystemLogger {
|
|
42
|
+
fields;
|
|
43
|
+
logLevel;
|
|
44
|
+
constructor(fields = {}, logLevel = 2) {
|
|
45
|
+
this.fields = fields;
|
|
46
|
+
this.logLevel = logLevel;
|
|
47
|
+
}
|
|
48
|
+
doLog(logger, message) {
|
|
49
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
53
|
+
}
|
|
54
|
+
log(message) {
|
|
55
|
+
if (this.logLevel > 2) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.doLog(console.log, message);
|
|
59
|
+
}
|
|
60
|
+
debug(message) {
|
|
61
|
+
if (this.logLevel > 1) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.doLog(console.debug, message);
|
|
65
|
+
}
|
|
66
|
+
error(message) {
|
|
67
|
+
if (this.logLevel > 3) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.doLog(console.error, message);
|
|
71
|
+
}
|
|
72
|
+
withLogLevel(level) {
|
|
73
|
+
return new _SystemLogger(this.fields, level);
|
|
74
|
+
}
|
|
75
|
+
withFields(fields) {
|
|
76
|
+
return new _SystemLogger(
|
|
77
|
+
{
|
|
78
|
+
...this.fields,
|
|
79
|
+
...fields
|
|
80
|
+
},
|
|
81
|
+
this.logLevel
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
withError(error) {
|
|
85
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
86
|
+
return this.withFields(fields);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var systemLogger = new SystemLogger();
|
|
90
|
+
|
|
91
|
+
// src/run/handlers/request-context.cts
|
|
92
|
+
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
93
|
+
var requestContextAsyncLocalStorage;
|
|
94
|
+
function getRequestContextAsyncLocalStorage() {
|
|
95
|
+
if (requestContextAsyncLocalStorage) {
|
|
96
|
+
return requestContextAsyncLocalStorage;
|
|
97
|
+
}
|
|
98
|
+
const extendedGlobalThis = globalThis;
|
|
99
|
+
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
100
|
+
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
101
|
+
}
|
|
102
|
+
const storage = new import_node_async_hooks.AsyncLocalStorage();
|
|
103
|
+
requestContextAsyncLocalStorage = storage;
|
|
104
|
+
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
105
|
+
return storage;
|
|
106
|
+
}
|
|
107
|
+
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
108
|
+
|
|
109
|
+
// src/run/handlers/wait-until.cts
|
|
110
|
+
var NEXT_REQUEST_CONTEXT_SYMBOL = Symbol.for("@next/request-context");
|
|
111
|
+
function setupWaitUntil() {
|
|
112
|
+
;
|
|
113
|
+
globalThis[NEXT_REQUEST_CONTEXT_SYMBOL] = {
|
|
114
|
+
get() {
|
|
115
|
+
return { waitUntil: getRequestContext()?.trackBackgroundWork };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
setupWaitUntil
|
|
122
|
+
});
|
package/dist/run/headers.js
CHANGED
|
@@ -4,201 +4,16 @@
|
|
|
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-BEIUVQZK.js";
|
|
14
|
+
import "../esm-chunks/chunk-K4RDUZYO.js";
|
|
15
|
+
import "../esm-chunks/chunk-TYCYFZ22.js";
|
|
7
16
|
import "../esm-chunks/chunk-OEQOKJGE.js";
|
|
8
|
-
|
|
9
|
-
// src/run/headers.ts
|
|
10
|
-
import { encodeBlobKey } from "../shared/blobkey.js";
|
|
11
|
-
import { getRegionalBlobStore } from "./regional-blob-store.cjs";
|
|
12
|
-
var ALL_VARIATIONS = Symbol.for("ALL_VARIATIONS");
|
|
13
|
-
var NetlifyVaryKeys = /* @__PURE__ */ new Set(["header", "language", "cookie", "query", "country"]);
|
|
14
|
-
var isNetlifyVaryKey = (key) => NetlifyVaryKeys.has(key);
|
|
15
|
-
var generateNetlifyVaryValues = ({
|
|
16
|
-
header,
|
|
17
|
-
language,
|
|
18
|
-
cookie,
|
|
19
|
-
query,
|
|
20
|
-
country
|
|
21
|
-
}) => {
|
|
22
|
-
const values = [];
|
|
23
|
-
if (query.length !== 0) {
|
|
24
|
-
if (query.includes(ALL_VARIATIONS)) {
|
|
25
|
-
values.push(`query`);
|
|
26
|
-
} else {
|
|
27
|
-
values.push(`query=${query.join(`|`)}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (header.length !== 0) {
|
|
31
|
-
values.push(`header=${header.join(`|`)}`);
|
|
32
|
-
}
|
|
33
|
-
if (language.length !== 0) {
|
|
34
|
-
values.push(`language=${language.join(`|`)}`);
|
|
35
|
-
}
|
|
36
|
-
if (cookie.length !== 0) {
|
|
37
|
-
values.push(`cookie=${cookie.join(`|`)}`);
|
|
38
|
-
}
|
|
39
|
-
if (country.length !== 0) {
|
|
40
|
-
values.push(`country=${country.join(`|`)}`);
|
|
41
|
-
}
|
|
42
|
-
return values.join(",");
|
|
43
|
-
};
|
|
44
|
-
var getHeaderValueArray = (header) => {
|
|
45
|
-
return header.split(",").map((value) => value.trim()).filter(Boolean);
|
|
46
|
-
};
|
|
47
|
-
var omitHeaderValues = (header, values) => {
|
|
48
|
-
const headerValues = getHeaderValueArray(header);
|
|
49
|
-
const filteredValues = headerValues.filter(
|
|
50
|
-
(value) => !values.some((val) => value.startsWith(val))
|
|
51
|
-
);
|
|
52
|
-
return filteredValues.join(", ");
|
|
53
|
-
};
|
|
54
|
-
var setVaryHeaders = (headers, request, { basePath, i18n }) => {
|
|
55
|
-
const netlifyVaryValues = {
|
|
56
|
-
header: ["x-nextjs-data", "x-next-debug-logging"],
|
|
57
|
-
language: [],
|
|
58
|
-
cookie: ["__prerender_bypass", "__next_preview_data"],
|
|
59
|
-
query: [],
|
|
60
|
-
country: []
|
|
61
|
-
};
|
|
62
|
-
const vary = headers.get("vary");
|
|
63
|
-
if (vary !== null) {
|
|
64
|
-
netlifyVaryValues.header.push(...getHeaderValueArray(vary));
|
|
65
|
-
}
|
|
66
|
-
const path = new URL(request.url).pathname;
|
|
67
|
-
const locales = i18n && i18n.localeDetection !== false ? i18n.locales : [];
|
|
68
|
-
if (locales.length > 1 && (path === "/" || path === basePath)) {
|
|
69
|
-
netlifyVaryValues.language.push(...locales);
|
|
70
|
-
netlifyVaryValues.cookie.push(`NEXT_LOCALE`);
|
|
71
|
-
}
|
|
72
|
-
const userNetlifyVary = headers.get("netlify-vary");
|
|
73
|
-
if (userNetlifyVary) {
|
|
74
|
-
const directives = getHeaderValueArray(userNetlifyVary);
|
|
75
|
-
for (const directive of directives) {
|
|
76
|
-
const [key, value] = directive.split("=");
|
|
77
|
-
if (key === "query" && !value) {
|
|
78
|
-
netlifyVaryValues.query.push(ALL_VARIATIONS);
|
|
79
|
-
} else if (value && isNetlifyVaryKey(key)) {
|
|
80
|
-
netlifyVaryValues[key].push(...value.split("|"));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
headers.set(`netlify-vary`, generateNetlifyVaryValues(netlifyVaryValues));
|
|
85
|
-
};
|
|
86
|
-
var adjustDateHeader = async ({
|
|
87
|
-
headers,
|
|
88
|
-
request,
|
|
89
|
-
span,
|
|
90
|
-
tracer,
|
|
91
|
-
requestContext
|
|
92
|
-
}) => {
|
|
93
|
-
const cacheState = headers.get("x-nextjs-cache");
|
|
94
|
-
const isServedFromCache = cacheState === "HIT" || cacheState === "STALE";
|
|
95
|
-
span.setAttributes({
|
|
96
|
-
"x-nextjs-cache": cacheState ?? void 0,
|
|
97
|
-
isServedFromCache
|
|
98
|
-
});
|
|
99
|
-
if (!isServedFromCache) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const key = new URL(request.url).pathname;
|
|
103
|
-
let lastModified;
|
|
104
|
-
if (requestContext.responseCacheGetLastModified) {
|
|
105
|
-
lastModified = requestContext.responseCacheGetLastModified;
|
|
106
|
-
} else {
|
|
107
|
-
span.recordException(
|
|
108
|
-
new Error("lastModified not found in requestContext, falling back to trying blobs")
|
|
109
|
-
);
|
|
110
|
-
span.setAttributes({
|
|
111
|
-
severity: "alert",
|
|
112
|
-
warning: true
|
|
113
|
-
});
|
|
114
|
-
const blobStore = getRegionalBlobStore({ consistency: "strong" });
|
|
115
|
-
const blobKey = await encodeBlobKey(key);
|
|
116
|
-
lastModified = await tracer.withActiveSpan(
|
|
117
|
-
"get cache to calculate date header",
|
|
118
|
-
async (getBlobForDateSpan) => {
|
|
119
|
-
getBlobForDateSpan.setAttributes({
|
|
120
|
-
key,
|
|
121
|
-
blobKey
|
|
122
|
-
});
|
|
123
|
-
const blob = await blobStore.get(blobKey, { type: "json" }) ?? {};
|
|
124
|
-
getBlobForDateSpan.addEvent(blob ? "Cache hit" : "Cache miss");
|
|
125
|
-
return blob.lastModified;
|
|
126
|
-
}
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
if (!lastModified) {
|
|
130
|
-
span.recordException(
|
|
131
|
-
new Error(
|
|
132
|
-
"lastModified not found in either requestContext or blobs, date header for cached response is not set"
|
|
133
|
-
)
|
|
134
|
-
);
|
|
135
|
-
span.setAttributes({
|
|
136
|
-
severity: "alert",
|
|
137
|
-
warning: true
|
|
138
|
-
});
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const lastModifiedDate = new Date(lastModified);
|
|
142
|
-
headers.set("x-nextjs-date", headers.get("date") ?? lastModifiedDate.toUTCString());
|
|
143
|
-
headers.set("date", lastModifiedDate.toUTCString());
|
|
144
|
-
};
|
|
145
|
-
var setCacheControlHeaders = ({ headers, status }, request, requestContext) => {
|
|
146
|
-
if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
147
|
-
const cdnCacheControl = (
|
|
148
|
-
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
149
|
-
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${requestContext.routeHandlerRevalidate === false ? 31536e3 : requestContext.routeHandlerRevalidate}, stale-while-revalidate=31536000, durable`
|
|
150
|
-
);
|
|
151
|
-
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (status === 404 && 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
|
-
}
|
|
158
|
-
const cacheControl = headers.get("cache-control");
|
|
159
|
-
if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
160
|
-
const browserCacheControl = omitHeaderValues(cacheControl, [
|
|
161
|
-
"s-maxage",
|
|
162
|
-
"stale-while-revalidate"
|
|
163
|
-
]);
|
|
164
|
-
const cdnCacheControl = (
|
|
165
|
-
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
166
|
-
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
|
|
167
|
-
...getHeaderValueArray(cacheControl).map(
|
|
168
|
-
(value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
|
|
169
|
-
),
|
|
170
|
-
"durable"
|
|
171
|
-
].join(", ")
|
|
172
|
-
);
|
|
173
|
-
headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
|
|
174
|
-
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (cacheControl === null && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control") && requestContext.usedFsRead) {
|
|
178
|
-
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
179
|
-
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
var setCacheTagsHeaders = (headers, requestContext) => {
|
|
183
|
-
if (requestContext.responseCacheTags) {
|
|
184
|
-
headers.set("netlify-cache-tag", requestContext.responseCacheTags.join(","));
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
var NEXT_CACHE_TO_CACHE_STATUS = {
|
|
188
|
-
HIT: `hit`,
|
|
189
|
-
MISS: `fwd=miss`,
|
|
190
|
-
STALE: `hit; fwd=stale`
|
|
191
|
-
};
|
|
192
|
-
var setCacheStatusHeader = (headers) => {
|
|
193
|
-
const nextCache = headers.get("x-nextjs-cache");
|
|
194
|
-
if (typeof nextCache === "string") {
|
|
195
|
-
if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
|
|
196
|
-
const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
|
|
197
|
-
headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
|
|
198
|
-
}
|
|
199
|
-
headers.delete("x-nextjs-cache");
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
17
|
export {
|
|
203
18
|
adjustDateHeader,
|
|
204
19
|
setCacheControlHeaders,
|