@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
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/run/handlers/request-context.cts
|
|
9
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
-
|
|
11
|
-
// node_modules/@netlify/functions/dist/chunk-C6P2IO65.mjs
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __esm = (fn, res) => function __init() {
|
|
14
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// node_modules/@netlify/functions/dist/chunk-ATZ7N7EG.mjs
|
|
18
|
-
import { env } from "process";
|
|
19
|
-
var systemLogTag;
|
|
20
|
-
var serializeError;
|
|
21
|
-
var LogLevel;
|
|
22
|
-
var SystemLogger;
|
|
23
|
-
var systemLogger;
|
|
24
|
-
var init_system_logger = __esm({
|
|
25
|
-
"src/lib/system_logger.ts"() {
|
|
26
|
-
systemLogTag = "__nfSystemLog";
|
|
27
|
-
serializeError = (error) => {
|
|
28
|
-
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
29
|
-
return {
|
|
30
|
-
error: error.message,
|
|
31
|
-
error_cause: cause,
|
|
32
|
-
error_stack: error.stack
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
36
|
-
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
37
|
-
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
38
|
-
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
39
|
-
return LogLevel2;
|
|
40
|
-
})(LogLevel || {});
|
|
41
|
-
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 (env.NETLIFY_DEV && !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
|
-
systemLogger = new SystemLogger();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// node_modules/@netlify/functions/dist/chunk-7ANA32NV.mjs
|
|
94
|
-
var init_internal = __esm({
|
|
95
|
-
"src/internal.ts"() {
|
|
96
|
-
init_system_logger();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// node_modules/@netlify/functions/dist/internal.mjs
|
|
101
|
-
init_internal();
|
|
102
|
-
|
|
103
|
-
// src/run/handlers/request-context.cts
|
|
104
|
-
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
105
|
-
var requestContextAsyncLocalStorage;
|
|
106
|
-
function getRequestContextAsyncLocalStorage() {
|
|
107
|
-
if (requestContextAsyncLocalStorage) {
|
|
108
|
-
return requestContextAsyncLocalStorage;
|
|
109
|
-
}
|
|
110
|
-
const extendedGlobalThis = globalThis;
|
|
111
|
-
if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
|
|
112
|
-
return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
|
|
113
|
-
}
|
|
114
|
-
const storage = new AsyncLocalStorage();
|
|
115
|
-
requestContextAsyncLocalStorage = storage;
|
|
116
|
-
extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
|
|
117
|
-
return storage;
|
|
118
|
-
}
|
|
119
|
-
var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
120
|
-
function getLogger() {
|
|
121
|
-
return getRequestContext()?.logger ?? systemLogger;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
getRequestContext,
|
|
126
|
-
getLogger
|
|
127
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/shared/blobkey.ts
|
|
9
|
-
import { Buffer } from "node:buffer";
|
|
10
|
-
import { webcrypto as crypto } from "node:crypto";
|
|
11
|
-
var maxLength = 180;
|
|
12
|
-
async function encodeBlobKey(key) {
|
|
13
|
-
const buffer = Buffer.from(key);
|
|
14
|
-
const base64 = buffer.toString("base64url");
|
|
15
|
-
if (base64.length <= maxLength) {
|
|
16
|
-
return base64;
|
|
17
|
-
}
|
|
18
|
-
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
19
|
-
const hash = Buffer.from(digest).toString("base64url");
|
|
20
|
-
return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
encodeBlobKey
|
|
25
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/run/constants.ts
|
|
9
|
-
import { resolve } from "node:path";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
-
var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
|
|
12
|
-
var PLUGIN_DIR = resolve(`${MODULE_DIR}../../..`);
|
|
13
|
-
var RUN_CONFIG = "run-config.json";
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
MODULE_DIR,
|
|
17
|
-
PLUGIN_DIR,
|
|
18
|
-
RUN_CONFIG
|
|
19
|
-
};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
wrapTracer
|
|
9
|
-
} from "./chunk-5QSXBV7L.js";
|
|
10
|
-
import {
|
|
11
|
-
init_esm,
|
|
12
|
-
trace
|
|
13
|
-
} from "./chunk-GNGHTHMQ.js";
|
|
14
|
-
import {
|
|
15
|
-
verifyNetlifyForms
|
|
16
|
-
} from "./chunk-ZSVHJNNY.js";
|
|
17
|
-
import {
|
|
18
|
-
require_out
|
|
19
|
-
} from "./chunk-KGYJQ2U2.js";
|
|
20
|
-
import {
|
|
21
|
-
encodeBlobKey
|
|
22
|
-
} from "./chunk-TYCYFZ22.js";
|
|
23
|
-
import {
|
|
24
|
-
__toESM
|
|
25
|
-
} from "./chunk-OEQOKJGE.js";
|
|
26
|
-
|
|
27
|
-
// src/build/content/static.ts
|
|
28
|
-
init_esm();
|
|
29
|
-
import { existsSync } from "node:fs";
|
|
30
|
-
import { cp, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
31
|
-
import { basename, join } from "node:path";
|
|
32
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
33
|
-
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
34
|
-
var copyStaticContent = async (ctx) => {
|
|
35
|
-
return tracer.withActiveSpan("copyStaticContent", async () => {
|
|
36
|
-
const srcDir = join(ctx.publishDir, "server/pages");
|
|
37
|
-
const destDir = ctx.blobDir;
|
|
38
|
-
const paths = await (0, import_fast_glob.default)("**/*.+(html|json)", {
|
|
39
|
-
cwd: srcDir,
|
|
40
|
-
extglob: true
|
|
41
|
-
});
|
|
42
|
-
const fallbacks = ctx.getFallbacks(await ctx.getPrerenderManifest());
|
|
43
|
-
try {
|
|
44
|
-
await mkdir(destDir, { recursive: true });
|
|
45
|
-
await Promise.all(
|
|
46
|
-
paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
|
|
47
|
-
const html = await readFile(join(srcDir, path), "utf-8");
|
|
48
|
-
verifyNetlifyForms(ctx, html);
|
|
49
|
-
const isFallback = fallbacks.includes(path.slice(0, -5));
|
|
50
|
-
await writeFile(
|
|
51
|
-
join(destDir, await encodeBlobKey(path)),
|
|
52
|
-
JSON.stringify({ html, isFallback }),
|
|
53
|
-
"utf-8"
|
|
54
|
-
);
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
ctx.failBuild("Failed assembling static pages for upload", error);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
var copyStaticAssets = async (ctx) => {
|
|
63
|
-
return tracer.withActiveSpan("copyStaticAssets", async (span) => {
|
|
64
|
-
try {
|
|
65
|
-
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
66
|
-
const { basePath } = await ctx.getRoutesManifest();
|
|
67
|
-
if (existsSync(ctx.resolveFromSiteDir("public"))) {
|
|
68
|
-
await cp(ctx.resolveFromSiteDir("public"), join(ctx.staticDir, basePath), {
|
|
69
|
-
recursive: true
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (existsSync(join(ctx.publishDir, "static"))) {
|
|
73
|
-
await cp(join(ctx.publishDir, "static"), join(ctx.staticDir, basePath, "_next/static"), {
|
|
74
|
-
recursive: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
} catch (error) {
|
|
78
|
-
span.end();
|
|
79
|
-
ctx.failBuild("Failed copying static assets", error);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
var setHeadersConfig = async (ctx) => {
|
|
84
|
-
const { basePath } = ctx.buildConfig;
|
|
85
|
-
ctx.netlifyConfig.headers.push({
|
|
86
|
-
for: `${basePath}/_next/static/*`,
|
|
87
|
-
values: {
|
|
88
|
-
"Cache-Control": "public, max-age=31536000, immutable"
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
var copyStaticExport = async (ctx) => {
|
|
93
|
-
await tracer.withActiveSpan("copyStaticExport", async () => {
|
|
94
|
-
if (!ctx.exportDetail?.outDirectory) {
|
|
95
|
-
ctx.failBuild("Export directory not found");
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
99
|
-
await cp(ctx.exportDetail.outDirectory, ctx.staticDir, { recursive: true });
|
|
100
|
-
} catch (error) {
|
|
101
|
-
ctx.failBuild("Failed copying static export", error);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
var publishStaticDir = async (ctx) => {
|
|
106
|
-
try {
|
|
107
|
-
await rm(ctx.tempPublishDir, { recursive: true, force: true });
|
|
108
|
-
await mkdir(basename(ctx.tempPublishDir), { recursive: true });
|
|
109
|
-
await rename(ctx.publishDir, ctx.tempPublishDir);
|
|
110
|
-
await rename(ctx.staticDir, ctx.publishDir);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
ctx.failBuild("Failed publishing static content", error instanceof Error ? { error } : {});
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var unpublishStaticDir = async (ctx) => {
|
|
116
|
-
try {
|
|
117
|
-
if (existsSync(ctx.tempPublishDir)) {
|
|
118
|
-
await rename(ctx.publishDir, ctx.staticDir);
|
|
119
|
-
await rename(ctx.tempPublishDir, ctx.publishDir);
|
|
120
|
-
}
|
|
121
|
-
} catch {
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
copyStaticContent,
|
|
127
|
-
copyStaticAssets,
|
|
128
|
-
setHeadersConfig,
|
|
129
|
-
copyStaticExport,
|
|
130
|
-
publishStaticDir,
|
|
131
|
-
unpublishStaticDir
|
|
132
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
getRequestContext
|
|
9
|
-
} from "./chunk-SGXRYMYQ.js";
|
|
10
|
-
import {
|
|
11
|
-
wrapTracer
|
|
12
|
-
} from "./chunk-5QSXBV7L.js";
|
|
13
|
-
import {
|
|
14
|
-
init_esm,
|
|
15
|
-
trace
|
|
16
|
-
} from "./chunk-GNGHTHMQ.js";
|
|
17
|
-
|
|
18
|
-
// src/run/handlers/tracer.cts
|
|
19
|
-
init_esm();
|
|
20
|
-
var spanMeta = /* @__PURE__ */ new WeakMap();
|
|
21
|
-
var spanCounter = /* @__PURE__ */ new WeakMap();
|
|
22
|
-
function spanHook(span) {
|
|
23
|
-
const originalEnd = span.end.bind(span);
|
|
24
|
-
span.end = (endTime) => {
|
|
25
|
-
originalEnd(endTime);
|
|
26
|
-
const meta = spanMeta.get(span);
|
|
27
|
-
if (meta) {
|
|
28
|
-
const requestContext = getRequestContext();
|
|
29
|
-
if (requestContext?.captureServerTiming) {
|
|
30
|
-
const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
|
|
31
|
-
const serverTiming = requestContext.serverTiming ?? "";
|
|
32
|
-
const currentRequestSpanCounter = spanCounter.get(requestContext) ?? 1;
|
|
33
|
-
requestContext.serverTiming = `${serverTiming}${serverTiming.length === 0 ? "" : ", "}s${currentRequestSpanCounter};dur=${duration};desc="${meta.name}"`;
|
|
34
|
-
spanCounter.set(requestContext, currentRequestSpanCounter + 1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
spanMeta.delete(span);
|
|
38
|
-
};
|
|
39
|
-
return span;
|
|
40
|
-
}
|
|
41
|
-
var tracer;
|
|
42
|
-
function getTracer() {
|
|
43
|
-
if (!tracer) {
|
|
44
|
-
const baseTracer = trace.getTracer("Next.js Runtime");
|
|
45
|
-
const startSpan = baseTracer.startSpan.bind(baseTracer);
|
|
46
|
-
baseTracer.startSpan = (...args) => {
|
|
47
|
-
const span = startSpan(...args);
|
|
48
|
-
spanMeta.set(span, { start: performance.now(), name: args[0] });
|
|
49
|
-
return spanHook(span);
|
|
50
|
-
};
|
|
51
|
-
const startActiveSpan = baseTracer.startActiveSpan.bind(baseTracer);
|
|
52
|
-
baseTracer.startActiveSpan = (...args) => {
|
|
53
|
-
const [name, ...restOfArgs] = args;
|
|
54
|
-
const augmentedArgs = restOfArgs.map((arg) => {
|
|
55
|
-
if (typeof arg === "function") {
|
|
56
|
-
return (span) => {
|
|
57
|
-
spanMeta.set(span, { start: performance.now(), name: args[0] });
|
|
58
|
-
spanHook(span);
|
|
59
|
-
return arg(span);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return arg;
|
|
63
|
-
});
|
|
64
|
-
return startActiveSpan(name, ...augmentedArgs);
|
|
65
|
-
};
|
|
66
|
-
tracer = wrapTracer(baseTracer);
|
|
67
|
-
}
|
|
68
|
-
return tracer;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
getTracer
|
|
73
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/run/revalidate.ts
|
|
9
|
-
import { isPromise } from "node:util/types";
|
|
10
|
-
function isRevalidateMethod(key, nextResponseField) {
|
|
11
|
-
return key === "revalidate" && typeof nextResponseField === "function";
|
|
12
|
-
}
|
|
13
|
-
var nextResponseProxy = (res, requestContext) => {
|
|
14
|
-
return new Proxy(res, {
|
|
15
|
-
get(target, key) {
|
|
16
|
-
const originalValue = Reflect.get(target, key);
|
|
17
|
-
if (isRevalidateMethod(key, originalValue)) {
|
|
18
|
-
return function newRevalidate(...args) {
|
|
19
|
-
requestContext.didPagesRouterOnDemandRevalidate = true;
|
|
20
|
-
const result = originalValue.apply(target, args);
|
|
21
|
-
if (result && isPromise(result)) {
|
|
22
|
-
requestContext.trackBackgroundWork(result);
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
return originalValue;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export {
|
|
33
|
-
nextResponseProxy
|
|
34
|
-
};
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
getRegionalBlobStore
|
|
9
|
-
} from "./chunk-K4RDUZYO.js";
|
|
10
|
-
import {
|
|
11
|
-
getLogger
|
|
12
|
-
} from "./chunk-SGXRYMYQ.js";
|
|
13
|
-
import {
|
|
14
|
-
encodeBlobKey
|
|
15
|
-
} from "./chunk-TYCYFZ22.js";
|
|
16
|
-
|
|
17
|
-
// src/run/headers.ts
|
|
18
|
-
var ALL_VARIATIONS = Symbol.for("ALL_VARIATIONS");
|
|
19
|
-
var NetlifyVaryKeys = /* @__PURE__ */ new Set(["header", "language", "cookie", "query", "country"]);
|
|
20
|
-
var isNetlifyVaryKey = (key) => NetlifyVaryKeys.has(key);
|
|
21
|
-
var generateNetlifyVaryValues = ({
|
|
22
|
-
header,
|
|
23
|
-
language,
|
|
24
|
-
cookie,
|
|
25
|
-
query,
|
|
26
|
-
country
|
|
27
|
-
}) => {
|
|
28
|
-
const values = [];
|
|
29
|
-
if (query.length !== 0) {
|
|
30
|
-
if (query.includes(ALL_VARIATIONS)) {
|
|
31
|
-
values.push(`query`);
|
|
32
|
-
} else {
|
|
33
|
-
values.push(`query=${query.join(`|`)}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (header.length !== 0) {
|
|
37
|
-
values.push(`header=${header.join(`|`)}`);
|
|
38
|
-
}
|
|
39
|
-
if (language.length !== 0) {
|
|
40
|
-
values.push(`language=${language.join(`|`)}`);
|
|
41
|
-
}
|
|
42
|
-
if (cookie.length !== 0) {
|
|
43
|
-
values.push(`cookie=${cookie.join(`|`)}`);
|
|
44
|
-
}
|
|
45
|
-
if (country.length !== 0) {
|
|
46
|
-
values.push(`country=${country.join(`|`)}`);
|
|
47
|
-
}
|
|
48
|
-
return values.join(",");
|
|
49
|
-
};
|
|
50
|
-
var getHeaderValueArray = (header) => {
|
|
51
|
-
return header.split(",").map((value) => value.trim()).filter(Boolean);
|
|
52
|
-
};
|
|
53
|
-
var omitHeaderValues = (header, values) => {
|
|
54
|
-
const headerValues = getHeaderValueArray(header);
|
|
55
|
-
const filteredValues = headerValues.filter(
|
|
56
|
-
(value) => !values.some((val) => value.startsWith(val))
|
|
57
|
-
);
|
|
58
|
-
return filteredValues.join(", ");
|
|
59
|
-
};
|
|
60
|
-
var setVaryHeaders = (headers, request, { basePath, i18n }) => {
|
|
61
|
-
const netlifyVaryValues = {
|
|
62
|
-
header: ["x-nextjs-data", "x-next-debug-logging"],
|
|
63
|
-
language: [],
|
|
64
|
-
cookie: ["__prerender_bypass", "__next_preview_data"],
|
|
65
|
-
query: ["__nextDataReq"],
|
|
66
|
-
country: []
|
|
67
|
-
};
|
|
68
|
-
const vary = headers.get("vary");
|
|
69
|
-
if (vary !== null) {
|
|
70
|
-
netlifyVaryValues.header.push(...getHeaderValueArray(vary));
|
|
71
|
-
}
|
|
72
|
-
const path = new URL(request.url).pathname;
|
|
73
|
-
const locales = i18n && i18n.localeDetection !== false ? i18n.locales : [];
|
|
74
|
-
if (locales.length > 1 && (path === "/" || path === basePath)) {
|
|
75
|
-
netlifyVaryValues.language.push(...locales);
|
|
76
|
-
netlifyVaryValues.cookie.push(`NEXT_LOCALE`);
|
|
77
|
-
}
|
|
78
|
-
const userNetlifyVary = headers.get("netlify-vary");
|
|
79
|
-
if (userNetlifyVary) {
|
|
80
|
-
const directives = getHeaderValueArray(userNetlifyVary);
|
|
81
|
-
for (const directive of directives) {
|
|
82
|
-
const [key, value] = directive.split("=");
|
|
83
|
-
if (key === "query" && !value) {
|
|
84
|
-
netlifyVaryValues.query.push(ALL_VARIATIONS);
|
|
85
|
-
} else if (value && isNetlifyVaryKey(key)) {
|
|
86
|
-
netlifyVaryValues[key].push(...value.split("|"));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
headers.set(`netlify-vary`, generateNetlifyVaryValues(netlifyVaryValues));
|
|
91
|
-
};
|
|
92
|
-
var adjustDateHeader = async ({
|
|
93
|
-
headers,
|
|
94
|
-
request,
|
|
95
|
-
span,
|
|
96
|
-
tracer,
|
|
97
|
-
requestContext
|
|
98
|
-
}) => {
|
|
99
|
-
const key = new URL(request.url).pathname;
|
|
100
|
-
let lastModified;
|
|
101
|
-
if (requestContext.responseCacheGetLastModified) {
|
|
102
|
-
lastModified = requestContext.responseCacheGetLastModified;
|
|
103
|
-
} else {
|
|
104
|
-
span.recordException(
|
|
105
|
-
new Error("lastModified not found in requestContext, falling back to trying blobs")
|
|
106
|
-
);
|
|
107
|
-
span.setAttributes({
|
|
108
|
-
severity: "alert",
|
|
109
|
-
warning: true
|
|
110
|
-
});
|
|
111
|
-
const blobStore = getRegionalBlobStore({ consistency: "strong" });
|
|
112
|
-
const blobKey = await encodeBlobKey(key);
|
|
113
|
-
lastModified = await tracer.withActiveSpan(
|
|
114
|
-
"get cache to calculate date header",
|
|
115
|
-
async (getBlobForDateSpan) => {
|
|
116
|
-
getBlobForDateSpan.setAttributes({
|
|
117
|
-
key,
|
|
118
|
-
blobKey
|
|
119
|
-
});
|
|
120
|
-
const blob = await blobStore.get(blobKey, { type: "json" }) ?? {};
|
|
121
|
-
getBlobForDateSpan.addEvent(blob ? "Cache hit" : "Cache miss");
|
|
122
|
-
return blob.lastModified;
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
if (!lastModified) {
|
|
127
|
-
span.recordException(
|
|
128
|
-
new Error(
|
|
129
|
-
"lastModified not found in either requestContext or blobs, date header for cached response is not set"
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
span.setAttributes({
|
|
133
|
-
severity: "alert",
|
|
134
|
-
warning: true
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const lastModifiedDate = new Date(lastModified);
|
|
139
|
-
headers.set("x-nextjs-date", headers.get("date") ?? lastModifiedDate.toUTCString());
|
|
140
|
-
headers.set("date", lastModifiedDate.toUTCString());
|
|
141
|
-
};
|
|
142
|
-
function setCacheControlFromRequestContext(headers, revalidate) {
|
|
143
|
-
const cdnCacheControl = (
|
|
144
|
-
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
145
|
-
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : `s-maxage=${revalidate || 31536e3}, stale-while-revalidate=31536000, durable`
|
|
146
|
-
);
|
|
147
|
-
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
148
|
-
}
|
|
149
|
-
var setCacheControlHeaders = ({ headers, status }, request, requestContext, nextConfig) => {
|
|
150
|
-
if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
151
|
-
setCacheControlFromRequestContext(headers, requestContext.routeHandlerRevalidate);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (status === 308 && request.url.endsWith("/") !== nextConfig.trailingSlash) {
|
|
155
|
-
getLogger().withFields({ trailingSlash: nextConfig.trailingSlash, location: headers.get("location") }).log("NetlifyHeadersHandler.trailingSlashRedirect");
|
|
156
|
-
}
|
|
157
|
-
const cacheControl = headers.get("cache-control");
|
|
158
|
-
if (status === 404) {
|
|
159
|
-
if (request.url.endsWith(".php")) {
|
|
160
|
-
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
161
|
-
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (process.env.CACHE_404_PAGE && request.url.endsWith("/404") && ["GET", "HEAD"].includes(request.method)) {
|
|
165
|
-
setCacheControlFromRequestContext(headers, requestContext.pageHandlerRevalidate);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
|
|
170
|
-
const browserCacheControl = omitHeaderValues(cacheControl, [
|
|
171
|
-
"s-maxage",
|
|
172
|
-
"stale-while-revalidate"
|
|
173
|
-
]);
|
|
174
|
-
const cdnCacheControl = (
|
|
175
|
-
// if we are serving already stale response, instruct edge to not attempt to cache that response
|
|
176
|
-
headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate, durable" : [
|
|
177
|
-
...getHeaderValueArray(cacheControl).map(
|
|
178
|
-
(value) => value === "stale-while-revalidate" ? "stale-while-revalidate=31536000" : value
|
|
179
|
-
),
|
|
180
|
-
"durable"
|
|
181
|
-
].join(", ")
|
|
182
|
-
);
|
|
183
|
-
headers.set("cache-control", browserCacheControl || "public, max-age=0, must-revalidate");
|
|
184
|
-
headers.set("netlify-cdn-cache-control", cdnCacheControl);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (cacheControl === null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control") && requestContext.usedFsReadForNonFallback) {
|
|
188
|
-
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
189
|
-
headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
var setCacheTagsHeaders = (headers, requestContext) => {
|
|
193
|
-
if (requestContext.responseCacheTags && (headers.has("cache-control") || headers.has("netlify-cdn-cache-control"))) {
|
|
194
|
-
headers.set("netlify-cache-tag", requestContext.responseCacheTags.join(","));
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
var NEXT_CACHE_TO_CACHE_STATUS = {
|
|
198
|
-
HIT: `hit`,
|
|
199
|
-
MISS: `fwd=miss`,
|
|
200
|
-
STALE: `hit; fwd=stale`
|
|
201
|
-
};
|
|
202
|
-
var setCacheStatusHeader = (headers, nextCache) => {
|
|
203
|
-
if (typeof nextCache === "string") {
|
|
204
|
-
if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
|
|
205
|
-
const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
|
|
206
|
-
headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
|
|
207
|
-
}
|
|
208
|
-
headers.delete("x-nextjs-cache");
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
export {
|
|
213
|
-
setVaryHeaders,
|
|
214
|
-
adjustDateHeader,
|
|
215
|
-
setCacheControlHeaders,
|
|
216
|
-
setCacheTagsHeaders,
|
|
217
|
-
setCacheStatusHeader
|
|
218
|
-
};
|