@vercel/next 4.0.5 → 4.0.7
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/index.js +14671 -46249
- package/dist/legacy-launcher.js +28 -10
- package/dist/server-launcher.js +18 -28
- package/dist/templated-launcher-shared.js +6 -14
- package/dist/templated-launcher.js +2 -11
- package/package.json +7 -5
- package/dist/create-serverless-config.js +0 -91
- package/dist/edge-function-source/constants.js +0 -8
- package/dist/edge-function-source/get-edge-function-source.js +0 -78
- package/dist/edge-function-source/get-edge-function.js +0 -138
- package/dist/edge-function-source/to-plain-headers.js +0 -87
- package/dist/legacy-versions.js +0 -338
- package/dist/server-build.js +0 -1330
- package/dist/sourcemapped.js +0 -121
- package/dist/utils.js +0 -1943
package/dist/legacy-launcher.js
CHANGED
@@ -1,16 +1,34 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
4
15
|
};
|
5
|
-
|
6
|
-
|
7
|
-
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
24
|
+
var import_next_server = __toESM(require("next-server"));
|
25
|
+
var import_url = __toESM(require("url"));
|
8
26
|
if (!process.env.NODE_ENV) {
|
9
|
-
|
10
|
-
|
27
|
+
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
28
|
+
process.env.NODE_ENV = region === "dev1" ? "development" : "production";
|
11
29
|
}
|
12
|
-
const app = (0,
|
30
|
+
const app = (0, import_next_server.default)({});
|
13
31
|
module.exports = (req, res) => {
|
14
|
-
|
15
|
-
|
32
|
+
const parsedUrl = import_url.default.parse(req.url || "", true);
|
33
|
+
app.render(req, res, "PATHNAME_PLACEHOLDER", parsedUrl.query, parsedUrl);
|
16
34
|
};
|
package/dist/server-launcher.js
CHANGED
@@ -1,39 +1,29 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
// The Next.js builder can emit the project in a subdirectory depending on how
|
4
|
-
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
5
|
-
// returns the proper path, we change the directory to the folder with the
|
6
|
-
// launcher. This mimics `yarn workspace run` behavior.
|
7
2
|
process.chdir(__dirname);
|
8
3
|
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
9
4
|
if (!process.env.NODE_ENV) {
|
10
|
-
|
5
|
+
process.env.NODE_ENV = region === "dev1" ? "development" : "production";
|
11
6
|
}
|
12
|
-
if (process.env.NODE_ENV !==
|
13
|
-
|
14
|
-
process.env.NODE_ENV
|
7
|
+
if (process.env.NODE_ENV !== "production" && region !== "dev1") {
|
8
|
+
console.warn(
|
9
|
+
`Warning: NODE_ENV was incorrectly set to "${process.env.NODE_ENV}", this value is being overridden to "production"`
|
10
|
+
);
|
11
|
+
process.env.NODE_ENV = "production";
|
15
12
|
}
|
16
|
-
|
17
|
-
// eslint-disable-next-line
|
18
|
-
const NextServer = require('__NEXT_SERVER_PATH__').default;
|
13
|
+
const NextServer = require("__NEXT_SERVER_PATH__").default;
|
19
14
|
const nextServer = new NextServer({
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
// @ts-ignore __NEXT_CONFIG__ value is injected
|
16
|
+
conf: __NEXT_CONFIG__,
|
17
|
+
dir: ".",
|
18
|
+
minimalMode: true,
|
19
|
+
customServer: false
|
25
20
|
});
|
26
21
|
const requestHandler = nextServer.getRequestHandler();
|
27
22
|
module.exports = async (req, res) => {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
// crash the lambda immediately to clean up any bad module state,
|
35
|
-
// this was previously handled in ___vc_bridge on an unhandled rejection
|
36
|
-
// but we can do this quicker by triggering here
|
37
|
-
process.exit(1);
|
38
|
-
}
|
23
|
+
try {
|
24
|
+
await requestHandler(req, res);
|
25
|
+
} catch (err) {
|
26
|
+
console.error(err);
|
27
|
+
process.exit(1);
|
28
|
+
}
|
39
29
|
};
|
@@ -1,22 +1,14 @@
|
|
1
1
|
"use strict";
|
2
|
-
// The Next.js builder can emit the project in a subdirectory depending on how
|
3
|
-
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
4
|
-
// returns the proper path, we change the directory to the folder with the
|
5
|
-
// launcher. This mimics `yarn workspace run` behavior.
|
6
2
|
process.chdir(__dirname);
|
7
3
|
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
8
4
|
if (!process.env.NODE_ENV) {
|
9
|
-
|
5
|
+
process.env.NODE_ENV = region === "dev1" ? "development" : "production";
|
10
6
|
}
|
11
|
-
if (process.env.NODE_ENV !==
|
12
|
-
|
13
|
-
process.env.NODE_ENV
|
7
|
+
if (process.env.NODE_ENV !== "production" && region !== "dev1") {
|
8
|
+
console.warn(
|
9
|
+
`Warning: NODE_ENV was incorrectly set to "${process.env.NODE_ENV}", this value is being overridden to "production"`
|
10
|
+
);
|
11
|
+
process.env.NODE_ENV = "production";
|
14
12
|
}
|
15
|
-
// @ts-ignore
|
16
|
-
// eslint-disable-next-line
|
17
13
|
let page = {};
|
18
|
-
// __LAUNCHER_PAGE_HANDLER__
|
19
|
-
// page.render is for React rendering
|
20
|
-
// page.default is for /api rendering
|
21
|
-
// page is for module.exports in /api
|
22
14
|
module.exports = page.render || page.default || page;
|
@@ -1,17 +1,8 @@
|
|
1
1
|
"use strict";
|
2
|
-
// The Next.js builder can emit the project in a subdirectory depending on how
|
3
|
-
// many folder levels of `node_modules` are traced. To ensure `process.cwd()`
|
4
|
-
// returns the proper path, we change the directory to the folder with the
|
5
|
-
// launcher. This mimics `yarn workspace run` behavior.
|
6
2
|
process.chdir(__dirname);
|
7
3
|
if (!process.env.NODE_ENV) {
|
8
|
-
|
9
|
-
|
4
|
+
const region = process.env.VERCEL_REGION || process.env.NOW_REGION;
|
5
|
+
process.env.NODE_ENV = region === "dev1" ? "development" : "production";
|
10
6
|
}
|
11
|
-
// @ts-ignore
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
13
7
|
const page = require(__LAUNCHER_PAGE_PATH__);
|
14
|
-
// page.render is for React rendering
|
15
|
-
// page.default is for /api rendering
|
16
|
-
// page is for module.exports in /api
|
17
8
|
module.exports = page.render || page.default || page;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/next",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.7",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
@@ -12,6 +12,9 @@
|
|
12
12
|
"files": [
|
13
13
|
"dist"
|
14
14
|
],
|
15
|
+
"dependencies": {
|
16
|
+
"@vercel/nft": "0.24.1"
|
17
|
+
},
|
15
18
|
"devDependencies": {
|
16
19
|
"@types/aws-lambda": "8.10.19",
|
17
20
|
"@types/buffer-crc32": "0.2.0",
|
@@ -20,14 +23,14 @@
|
|
20
23
|
"@types/find-up": "4.0.0",
|
21
24
|
"@types/fs-extra": "8.0.0",
|
22
25
|
"@types/glob": "7.1.3",
|
26
|
+
"@types/jest": "29.5.5",
|
23
27
|
"@types/next-server": "8.0.0",
|
24
28
|
"@types/node": "14.18.33",
|
25
29
|
"@types/resolve-from": "5.0.1",
|
26
30
|
"@types/semver": "6.0.0",
|
27
31
|
"@types/text-table": "0.2.1",
|
28
32
|
"@types/webpack-sources": "3.2.0",
|
29
|
-
"@vercel/build-utils": "7.2.
|
30
|
-
"@vercel/nft": "0.22.5",
|
33
|
+
"@vercel/build-utils": "7.2.1",
|
31
34
|
"@vercel/routing-utils": "3.0.0",
|
32
35
|
"async-sema": "3.0.1",
|
33
36
|
"buffer-crc32": "0.2.13",
|
@@ -53,8 +56,7 @@
|
|
53
56
|
"webpack-sources": "3.2.3"
|
54
57
|
},
|
55
58
|
"scripts": {
|
56
|
-
"build": "node build.
|
57
|
-
"build-dev": "node build.js --dev",
|
59
|
+
"build": "node build.mjs",
|
58
60
|
"test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail --runInBand --testTimeout=360000",
|
59
61
|
"test-unit": "pnpm test test/unit/",
|
60
62
|
"test-next-local": "pnpm test test/integration/*.test.js test/integration/*.test.ts",
|
@@ -1,91 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
7
|
-
const path_1 = __importDefault(require("path"));
|
8
|
-
const semver_1 = __importDefault(require("semver"));
|
9
|
-
const utils_1 = require("./utils");
|
10
|
-
function getCustomData(importName, target) {
|
11
|
-
return `
|
12
|
-
// @ts-nocheck
|
13
|
-
module.exports = function(...args) {
|
14
|
-
let original = require('./${importName}');
|
15
|
-
|
16
|
-
const finalConfig = {};
|
17
|
-
const target = { target: '${target}' };
|
18
|
-
|
19
|
-
if (typeof original === 'function' && original.constructor.name === 'AsyncFunction') {
|
20
|
-
// AsyncFunctions will become promises
|
21
|
-
original = original(...args);
|
22
|
-
}
|
23
|
-
|
24
|
-
if (original instanceof Promise) {
|
25
|
-
// Special case for promises, as it's currently not supported
|
26
|
-
// and will just error later on
|
27
|
-
return original
|
28
|
-
.then((orignalConfig) => Object.assign(finalConfig, orignalConfig))
|
29
|
-
.then((config) => Object.assign(config, target));
|
30
|
-
} else if (typeof original === 'function') {
|
31
|
-
Object.assign(finalConfig, original(...args));
|
32
|
-
} else if (typeof original === 'object') {
|
33
|
-
Object.assign(finalConfig, original);
|
34
|
-
}
|
35
|
-
|
36
|
-
Object.assign(finalConfig, target);
|
37
|
-
|
38
|
-
return finalConfig;
|
39
|
-
}
|
40
|
-
`.trim();
|
41
|
-
}
|
42
|
-
function getDefaultData(target) {
|
43
|
-
return `
|
44
|
-
// @ts-nocheck
|
45
|
-
module.exports = { target: '${target}' };
|
46
|
-
`.trim();
|
47
|
-
}
|
48
|
-
async function createServerlessConfig(workPath, entryPath, nextVersion) {
|
49
|
-
let target = 'serverless';
|
50
|
-
if (nextVersion) {
|
51
|
-
try {
|
52
|
-
if (semver_1.default.gte(nextVersion, utils_1.ExperimentalTraceVersion)) {
|
53
|
-
target = 'experimental-serverless-trace';
|
54
|
-
}
|
55
|
-
}
|
56
|
-
catch (_ignored
|
57
|
-
// eslint-disable-next-line
|
58
|
-
) { }
|
59
|
-
}
|
60
|
-
const primaryConfigPath = path_1.default.join(entryPath, 'next.config.js');
|
61
|
-
const secondaryConfigPath = path_1.default.join(workPath, 'next.config.js');
|
62
|
-
const backupConfigName = `next.config.__vercel_builder_backup__.js`;
|
63
|
-
const hasPrimaryConfig = fs_extra_1.default.existsSync(primaryConfigPath);
|
64
|
-
const hasSecondaryConfig = fs_extra_1.default.existsSync(secondaryConfigPath);
|
65
|
-
let configPath;
|
66
|
-
let backupConfigPath;
|
67
|
-
if (hasPrimaryConfig) {
|
68
|
-
// Prefer primary path
|
69
|
-
configPath = primaryConfigPath;
|
70
|
-
backupConfigPath = path_1.default.join(entryPath, backupConfigName);
|
71
|
-
}
|
72
|
-
else if (hasSecondaryConfig) {
|
73
|
-
// Work with secondary path (some monorepo setups)
|
74
|
-
configPath = secondaryConfigPath;
|
75
|
-
backupConfigPath = path_1.default.join(workPath, backupConfigName);
|
76
|
-
}
|
77
|
-
else {
|
78
|
-
// Default to primary path for creation
|
79
|
-
configPath = primaryConfigPath;
|
80
|
-
backupConfigPath = path_1.default.join(entryPath, backupConfigName);
|
81
|
-
}
|
82
|
-
if (fs_extra_1.default.existsSync(configPath)) {
|
83
|
-
await fs_extra_1.default.rename(configPath, backupConfigPath);
|
84
|
-
await fs_extra_1.default.writeFile(configPath, getCustomData(backupConfigName, target));
|
85
|
-
}
|
86
|
-
else {
|
87
|
-
await fs_extra_1.default.writeFile(configPath, getDefaultData(target));
|
88
|
-
}
|
89
|
-
return target;
|
90
|
-
}
|
91
|
-
exports.default = createServerlessConfig;
|
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.EDGE_FUNCTION_SIZE_LIMIT = void 0;
|
4
|
-
const utils_1 = require("../utils");
|
5
|
-
/**
|
6
|
-
* The maximum size of a *compressed* edge function.
|
7
|
-
*/
|
8
|
-
exports.EDGE_FUNCTION_SIZE_LIMIT = 4 * utils_1.MIB;
|
@@ -1,78 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.getNextjsEdgeFunctionSource = void 0;
|
7
|
-
const fs_extra_1 = require("fs-extra");
|
8
|
-
const webpack_sources_1 = require("webpack-sources");
|
9
|
-
const sourcemapped_1 = require("../sourcemapped");
|
10
|
-
const path_1 = require("path");
|
11
|
-
const constants_1 = require("./constants");
|
12
|
-
const zlib_1 = __importDefault(require("zlib"));
|
13
|
-
const util_1 = require("util");
|
14
|
-
const utils_1 = require("../utils");
|
15
|
-
// @ts-ignore this is a prebuilt file, based on `../../scripts/build-edge-function-template.js`
|
16
|
-
const ___get_nextjs_edge_function_js_1 = __importDefault(require("../../dist/___get-nextjs-edge-function.js"));
|
17
|
-
const gzip = (0, util_1.promisify)(zlib_1.default.gzip);
|
18
|
-
/**
|
19
|
-
* Allows to get the source code for a Next.js Edge Function where the output
|
20
|
-
* is defined by a set of filePaths that compose all chunks. Those will write
|
21
|
-
* to a global namespace _ENTRIES. The Next.js parameters will allow to adapt
|
22
|
-
* the function into the core Edge Function signature.
|
23
|
-
*
|
24
|
-
* @param filePaths Array of relative file paths for the function chunks.
|
25
|
-
* @param params Next.js parameters to adapt it to core edge functions.
|
26
|
-
* @param outputDir The output directory the files in `filePaths` stored in.
|
27
|
-
* @returns The source code of the edge function.
|
28
|
-
*/
|
29
|
-
async function getNextjsEdgeFunctionSource(filePaths, params, outputDir, wasm) {
|
30
|
-
const chunks = new webpack_sources_1.ConcatSource((0, sourcemapped_1.raw)(`let _ENTRIES = {};`));
|
31
|
-
for (const filePath of filePaths) {
|
32
|
-
const fullFilePath = (0, path_1.join)(outputDir, filePath);
|
33
|
-
const content = await (0, fs_extra_1.readFile)(fullFilePath, 'utf8');
|
34
|
-
chunks.add((0, sourcemapped_1.raw)(`\n/**/;`));
|
35
|
-
chunks.add(await (0, sourcemapped_1.fileToSource)(content, filePath, fullFilePath));
|
36
|
-
}
|
37
|
-
const text = chunks.source();
|
38
|
-
/**
|
39
|
-
* We validate at this point because we want to verify against user code.
|
40
|
-
* It should not count the Worker wrapper nor the Next.js wrapper.
|
41
|
-
*/
|
42
|
-
const wasmFiles = (wasm ?? []).map(({ filePath }) => (0, path_1.join)(outputDir, filePath));
|
43
|
-
await validateSize(text, wasmFiles);
|
44
|
-
// Wrap to fake module.exports
|
45
|
-
const getPageMatchCode = `(function () {
|
46
|
-
const module = { exports: {}, loaded: false };
|
47
|
-
const fn = (function(module,exports) {${___get_nextjs_edge_function_js_1.default}\n});
|
48
|
-
fn(module, module.exports);
|
49
|
-
return module.exports;
|
50
|
-
})`;
|
51
|
-
return (0, sourcemapped_1.sourcemapped) `
|
52
|
-
${(0, sourcemapped_1.raw)(getWasmImportStatements(wasm))}
|
53
|
-
${chunks};
|
54
|
-
export default ${(0, sourcemapped_1.raw)(getPageMatchCode)}.call({}).default(
|
55
|
-
${(0, sourcemapped_1.raw)(JSON.stringify(params))}
|
56
|
-
)`;
|
57
|
-
}
|
58
|
-
exports.getNextjsEdgeFunctionSource = getNextjsEdgeFunctionSource;
|
59
|
-
function getWasmImportStatements(wasm = []) {
|
60
|
-
return wasm
|
61
|
-
.filter(({ name }) => name.startsWith('wasm_'))
|
62
|
-
.map(({ name }) => {
|
63
|
-
const pathname = `/wasm/${name}.wasm`;
|
64
|
-
return `const ${name} = require(${JSON.stringify(pathname)});`;
|
65
|
-
})
|
66
|
-
.join('\n');
|
67
|
-
}
|
68
|
-
async function validateSize(script, wasmFiles) {
|
69
|
-
const buffers = [Buffer.from(script, 'utf8')];
|
70
|
-
for (const filePath of wasmFiles) {
|
71
|
-
buffers.push(await (0, fs_extra_1.readFile)(filePath));
|
72
|
-
}
|
73
|
-
const content = Buffer.concat(buffers);
|
74
|
-
const gzipped = await gzip(content);
|
75
|
-
if (gzipped.length > constants_1.EDGE_FUNCTION_SIZE_LIMIT) {
|
76
|
-
throw new Error(`Exceeds maximum edge function size: ${(0, utils_1.prettyBytes)(gzipped.length)} / ${(0, utils_1.prettyBytes)(constants_1.EDGE_FUNCTION_SIZE_LIMIT)}`);
|
77
|
-
}
|
78
|
-
}
|
@@ -1,138 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/// <reference lib="DOM" />
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
const to_plain_headers_1 = require("./to-plain-headers");
|
5
|
-
/**
|
6
|
-
* A template to adapt the Next.js Edge Function signature into the core Edge
|
7
|
-
* Function signature. This will automatically inject parameters that are
|
8
|
-
* missing in default Edge Functions from the provided configuration
|
9
|
-
* parameters. Static and Dynamic RegExp are calculated in the module scope
|
10
|
-
* to avoid recomputing them for each function invocation.
|
11
|
-
*/
|
12
|
-
function getNextjsEdgeFunction(params) {
|
13
|
-
const staticRoutes = params.staticRoutes.map(route => ({
|
14
|
-
regexp: new RegExp(route.namedRegex),
|
15
|
-
page: route.page,
|
16
|
-
}));
|
17
|
-
const dynamicRoutes = params.dynamicRoutes?.map(route => ({
|
18
|
-
regexp: new RegExp(route.namedRegex),
|
19
|
-
page: route.page,
|
20
|
-
})) || [];
|
21
|
-
return async function edgeFunction(request, context) {
|
22
|
-
let pathname = new URL(request.url).pathname;
|
23
|
-
let pageMatch = {};
|
24
|
-
// Remove the basePath from the URL
|
25
|
-
if (params.nextConfig?.basePath) {
|
26
|
-
if (pathname.startsWith(params.nextConfig.basePath)) {
|
27
|
-
pathname = pathname.replace(params.nextConfig.basePath, '') || '/';
|
28
|
-
}
|
29
|
-
}
|
30
|
-
// Remove the locale from the URL
|
31
|
-
if (params.nextConfig?.i18n) {
|
32
|
-
for (const locale of params.nextConfig.i18n.locales) {
|
33
|
-
const regexp = new RegExp(`^/${locale}($|/)`, 'i');
|
34
|
-
if (pathname.match(regexp)) {
|
35
|
-
pathname = pathname.replace(regexp, '/') || '/';
|
36
|
-
break;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
}
|
40
|
-
// Find the page match that will happen if there are no assets matching
|
41
|
-
for (const route of staticRoutes) {
|
42
|
-
const result = route.regexp.exec(pathname);
|
43
|
-
if (result) {
|
44
|
-
pageMatch.name = route.page;
|
45
|
-
break;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
if (!pageMatch.name) {
|
49
|
-
const isApi = isApiRoute(pathname);
|
50
|
-
for (const route of dynamicRoutes || []) {
|
51
|
-
/**
|
52
|
-
* Dynamic API routes should not be checked against dynamic non API
|
53
|
-
* routes so we skip it in such case. For example, a request to
|
54
|
-
* /api/test should not match /pages/[slug].test having:
|
55
|
-
* - pages/api/foo.js
|
56
|
-
* - pages/[slug]/test.js
|
57
|
-
*/
|
58
|
-
if (isApi && !isApiRoute(route.page)) {
|
59
|
-
continue;
|
60
|
-
}
|
61
|
-
const result = route.regexp.exec(pathname);
|
62
|
-
if (result) {
|
63
|
-
pageMatch = {
|
64
|
-
name: route.page,
|
65
|
-
params: result.groups,
|
66
|
-
};
|
67
|
-
break;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
// Invoke the function injecting missing parameters
|
72
|
-
const result = await _ENTRIES[`middleware_${params.name}`].default.call({}, {
|
73
|
-
request: {
|
74
|
-
url: request.url,
|
75
|
-
method: request.method,
|
76
|
-
headers: (0, to_plain_headers_1.toPlainHeaders)(request.headers),
|
77
|
-
ip: header(request.headers, IncomingHeaders.Ip),
|
78
|
-
geo: {
|
79
|
-
city: header(request.headers, IncomingHeaders.City, true),
|
80
|
-
country: header(request.headers, IncomingHeaders.Country, true),
|
81
|
-
latitude: header(request.headers, IncomingHeaders.Latitude),
|
82
|
-
longitude: header(request.headers, IncomingHeaders.Longitude),
|
83
|
-
region: header(request.headers, IncomingHeaders.Region, true),
|
84
|
-
},
|
85
|
-
nextConfig: params.nextConfig,
|
86
|
-
page: pageMatch,
|
87
|
-
body: request.body,
|
88
|
-
},
|
89
|
-
});
|
90
|
-
context.waitUntil(result.waitUntil);
|
91
|
-
return result.response;
|
92
|
-
};
|
93
|
-
}
|
94
|
-
exports.default = getNextjsEdgeFunction;
|
95
|
-
/**
|
96
|
-
* Allows to get a header value by name but falling back to `undefined` when
|
97
|
-
* the value does not exist. Optionally, we can make this function decode
|
98
|
-
* what it reads for certain cases.
|
99
|
-
*
|
100
|
-
* @param headers The Headers object.
|
101
|
-
* @param name The name of the header to extract.
|
102
|
-
* @param decode Tells if we should decode the value.
|
103
|
-
* @returns The header value or undefined.
|
104
|
-
*/
|
105
|
-
function header(headers, name, decode = false) {
|
106
|
-
const value = headers.get(name) || undefined;
|
107
|
-
return decode && value ? decodeURIComponent(value) : value;
|
108
|
-
}
|
109
|
-
function isApiRoute(path) {
|
110
|
-
return path === '/api' || path.startsWith('/api/');
|
111
|
-
}
|
112
|
-
var IncomingHeaders;
|
113
|
-
(function (IncomingHeaders) {
|
114
|
-
/**
|
115
|
-
* City of the original client IP calculated by Vercel Proxy.
|
116
|
-
*/
|
117
|
-
IncomingHeaders["City"] = "x-vercel-ip-city";
|
118
|
-
/**
|
119
|
-
* Country of the original client IP calculated by Vercel Proxy.
|
120
|
-
*/
|
121
|
-
IncomingHeaders["Country"] = "x-vercel-ip-country";
|
122
|
-
/**
|
123
|
-
* Ip from Vercel Proxy. Do not confuse it with the client Ip.
|
124
|
-
*/
|
125
|
-
IncomingHeaders["Ip"] = "x-real-ip";
|
126
|
-
/**
|
127
|
-
* Latitude of the original client IP calculated by Vercel Proxy.
|
128
|
-
*/
|
129
|
-
IncomingHeaders["Latitude"] = "x-vercel-ip-latitude";
|
130
|
-
/**
|
131
|
-
* Longitude of the original client IP calculated by Vercel Proxy.
|
132
|
-
*/
|
133
|
-
IncomingHeaders["Longitude"] = "x-vercel-ip-longitude";
|
134
|
-
/**
|
135
|
-
* Region of the original client IP calculated by Vercel Proxy.
|
136
|
-
*/
|
137
|
-
IncomingHeaders["Region"] = "x-vercel-ip-country-region";
|
138
|
-
})(IncomingHeaders || (IncomingHeaders = {}));
|
@@ -1,87 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.splitCookiesString = exports.toPlainHeaders = void 0;
|
4
|
-
/**
|
5
|
-
* Transforms a standard Headers object into a plean Headers object. This is
|
6
|
-
* done to support a plain format for headers which is used in the Edge
|
7
|
-
* Function signature.
|
8
|
-
*
|
9
|
-
* @param headers Headers from the original request.
|
10
|
-
* @returns The same headers formatted as Node Headers.
|
11
|
-
*/
|
12
|
-
function toPlainHeaders(headers) {
|
13
|
-
const result = {};
|
14
|
-
if (!headers)
|
15
|
-
return result;
|
16
|
-
headers.forEach((value, key) => {
|
17
|
-
result[key] = value;
|
18
|
-
if (key.toLowerCase() === 'set-cookie') {
|
19
|
-
result[key] = splitCookiesString(value);
|
20
|
-
}
|
21
|
-
});
|
22
|
-
return result;
|
23
|
-
}
|
24
|
-
exports.toPlainHeaders = toPlainHeaders;
|
25
|
-
/**
|
26
|
-
* Set-Cookie header field-values are sometimes comma joined in one string.
|
27
|
-
* This splits them without choking on commas that are within a single
|
28
|
-
* set-cookie field-value, such as in the Expires portion. This is uncommon,
|
29
|
-
* but explicitly allowed (https://tools.ietf.org/html/rfc2616#section-4.2)
|
30
|
-
*/
|
31
|
-
function splitCookiesString(cookiesString) {
|
32
|
-
const cookiesStrings = [];
|
33
|
-
let pos = 0;
|
34
|
-
let start;
|
35
|
-
let ch;
|
36
|
-
let lastComma;
|
37
|
-
let nextStart;
|
38
|
-
let cookiesSeparatorFound;
|
39
|
-
function skipWhitespace() {
|
40
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos)))
|
41
|
-
pos += 1;
|
42
|
-
return pos < cookiesString.length;
|
43
|
-
}
|
44
|
-
function notSpecialChar() {
|
45
|
-
ch = cookiesString.charAt(pos);
|
46
|
-
return ch !== '=' && ch !== ';' && ch !== ',';
|
47
|
-
}
|
48
|
-
while (pos < cookiesString.length) {
|
49
|
-
start = pos;
|
50
|
-
cookiesSeparatorFound = false;
|
51
|
-
while (skipWhitespace()) {
|
52
|
-
ch = cookiesString.charAt(pos);
|
53
|
-
if (ch === ',') {
|
54
|
-
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
55
|
-
lastComma = pos;
|
56
|
-
pos += 1;
|
57
|
-
skipWhitespace();
|
58
|
-
nextStart = pos;
|
59
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
60
|
-
pos += 1;
|
61
|
-
}
|
62
|
-
// currently special character
|
63
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === '=') {
|
64
|
-
// we found cookies separator
|
65
|
-
cookiesSeparatorFound = true;
|
66
|
-
// pos is inside the next cookie, so back up and return it.
|
67
|
-
pos = nextStart;
|
68
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
69
|
-
start = pos;
|
70
|
-
}
|
71
|
-
else {
|
72
|
-
// in param ',' or param separator ';',
|
73
|
-
// we continue from that comma
|
74
|
-
pos = lastComma + 1;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
else {
|
78
|
-
pos += 1;
|
79
|
-
}
|
80
|
-
}
|
81
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
82
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
83
|
-
}
|
84
|
-
}
|
85
|
-
return cookiesStrings;
|
86
|
-
}
|
87
|
-
exports.splitCookiesString = splitCookiesString;
|