@ngrok/app-server 0.3.2 → 0.3.4
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 +63 -23
- package/dist/brotli-only-DrA29Ecw.js +97 -0
- package/dist/brotli-only-DrA29Ecw.js.map +1 -0
- package/dist/{build-id-C6sYO9Yp.js → build-id-B0448vZH.js} +27 -2
- package/dist/build-id-B0448vZH.js.map +1 -0
- package/dist/{build-manifest-UDNk81Ce.js → build-manifest-DBMWe3Lx.js} +12 -2
- package/dist/build-manifest-DBMWe3Lx.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/client-browser.js +1 -1
- package/dist/client.js +1 -1
- package/dist/compress-JuJf2HaO.js +377 -0
- package/dist/compress-JuJf2HaO.js.map +1 -0
- package/dist/{compression-7_gToa8R.js → compression-CT2mWlKM.js} +9 -2
- package/dist/compression-CT2mWlKM.js.map +1 -0
- package/dist/{create-server-D0De6R7Q.js → create-server-BX2rH6-E.js} +616 -547
- package/dist/create-server-BX2rH6-E.js.map +1 -0
- package/dist/{create-server-kzZWd_Lo.d.ts → create-server-kxyhCdhv.d.ts} +50 -13
- package/dist/{entry-DuGgSKeB.d.ts → entry-CNL4OsEn.d.ts} +39 -3
- package/dist/entry-ChHgs269.js +352 -0
- package/dist/entry-ChHgs269.js.map +1 -0
- package/dist/{index-Bo5G9LuQ.d.ts → index-B8LsM6Mh.d.ts} +26 -1
- package/dist/index.d.ts +14 -23
- package/dist/index.js +3 -3
- package/dist/{load-entry-Bodyd2Ok.js → load-entry-BOgJPt1I.js} +4 -4
- package/dist/{load-entry-Bodyd2Ok.js.map → load-entry-BOgJPt1I.js.map} +1 -1
- package/dist/{node-C1qudLs_.js → node-B0AYf_IA.js} +5 -4
- package/dist/{node-C1qudLs_.js.map → node-B0AYf_IA.js.map} +1 -1
- package/dist/{node-tBVQPjQv.js → node-C0Ad7CVL.js} +2 -2
- package/dist/{node-tBVQPjQv.js.map → node-C0Ad7CVL.js.map} +1 -1
- package/dist/node-vite.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/react-router-vite.d.ts +1 -1
- package/dist/react-router.d.ts +3 -2
- package/dist/react-router.js +31 -2
- package/dist/react-router.js.map +1 -1
- package/dist/{response-writer-B7FoJjEE.js → response-writer-DzvUAz9x.js} +3 -3
- package/dist/response-writer-DzvUAz9x.js.map +1 -0
- package/dist/{script-hashes-C6hQ5XnP.js → script-hashes-CU7P9oZU.js} +2 -2
- package/dist/{script-hashes-C6hQ5XnP.js.map → script-hashes-CU7P9oZU.js.map} +1 -1
- package/dist/{serve-caOkS3o5.js → serve-BUJ7ZonG.js} +2 -2
- package/dist/{serve-caOkS3o5.js.map → serve-BUJ7ZonG.js.map} +1 -1
- package/dist/{stale-build-navigation-PnMLtTF8.js → stale-build-navigation-rg5xxmTr.js} +2 -2
- package/dist/{stale-build-navigation-PnMLtTF8.js.map → stale-build-navigation-rg5xxmTr.js.map} +1 -1
- package/dist/{start-DREqYrZh.js → start-DiQf9ttp.js} +36 -8
- package/dist/start-DiQf9ttp.js.map +1 -0
- package/dist/{static-files-Beju9riB.js → static-files-C2ea8KQ6.js} +11 -3
- package/dist/static-files-C2ea8KQ6.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +1 -1
- package/dist/tanstack-start.d.ts +2 -2
- package/dist/{tcp-Dd1Mt6sN.js → tcp-Bws6oEau.js} +2 -2
- package/dist/{tcp-Dd1Mt6sN.js.map → tcp-Bws6oEau.js.map} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +4 -4
- package/dist/{trailing-slash-BrymAEGv.d.ts → trailing-slash-DeOUxMYo.d.ts} +2 -2
- package/dist/{types-CEvzAmcn.d.ts → types-BKJxtIuj.d.ts} +24 -3
- package/dist/vercel-pages.d.ts +32 -0
- package/dist/vercel-pages.js +54 -0
- package/dist/vercel-pages.js.map +1 -0
- package/dist/vercel-vite.d.ts +30 -9
- package/dist/vercel-vite.js +183 -20
- package/dist/vercel-vite.js.map +1 -1
- package/dist/vercel.d.ts +4 -3
- package/dist/vercel.js +7 -5
- package/dist/vercel.js.map +1 -1
- package/dist/{vite-tTxVimP6.js → vite-DPiSKHDn.js} +182 -51
- package/dist/vite-DPiSKHDn.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +2 -1
- package/dist/build-id-C6sYO9Yp.js.map +0 -1
- package/dist/build-manifest-UDNk81Ce.js.map +0 -1
- package/dist/compression-7_gToa8R.js.map +0 -1
- package/dist/create-server-D0De6R7Q.js.map +0 -1
- package/dist/entry-UDsxuqBC.js +0 -116
- package/dist/entry-UDsxuqBC.js.map +0 -1
- package/dist/gzip-Doi4wqjX.js +0 -294
- package/dist/gzip-Doi4wqjX.js.map +0 -1
- package/dist/response-writer-B7FoJjEE.js.map +0 -1
- package/dist/start-DREqYrZh.js.map +0 -1
- package/dist/static-files-Beju9riB.js.map +0 -1
- package/dist/vite-tTxVimP6.js.map +0 -1
package/dist/vercel-vite.js
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import {
|
|
1
|
+
import { r as copyName } from "./compression-CT2mWlKM.js";
|
|
2
|
+
import { r as hasDotSegment } from "./static-files-C2ea8KQ6.js";
|
|
3
|
+
import { t as BROTLI_ONLY_LIST } from "./brotli-only-DrA29Ecw.js";
|
|
4
|
+
import { copyFileSync, cpSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
5
|
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
4
8
|
|
|
5
9
|
// src/vercel/vite.ts
|
|
6
|
-
/** The hashed files of the client build. Their names change with their content. */
|
|
7
|
-
const ASSETS = "/assets/";
|
|
8
10
|
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
11
|
+
/** The most routes of a deployment. See https://vercel.com/docs/limits. */
|
|
12
|
+
const ROUTE_LIMIT = 2048;
|
|
13
|
+
/**
|
|
14
|
+
* The URL path under `static/` of the bodies of the pages that the CDN
|
|
15
|
+
* serves. A route sends a request for it to the function, so a page has one
|
|
16
|
+
* URL.
|
|
17
|
+
*/
|
|
18
|
+
const PAGES = "/_app-server/pages";
|
|
19
|
+
/**
|
|
20
|
+
* The script that finds the pages that the CDN serves. Why the source in a
|
|
21
|
+
* `.ts` module: the tests of this package run the source, and Node.js runs a
|
|
22
|
+
* `.ts` file with no import of its own.
|
|
23
|
+
*/
|
|
24
|
+
const PAGES_SCRIPT = fileURLToPath(new URL(import.meta.url.endsWith(".ts") ? "./pages.ts" : "./vercel-pages.js", import.meta.url));
|
|
25
|
+
/** A case-insensitive pattern for `text/markdown`, in the regular expression syntax of any engine. */
|
|
26
|
+
const MARKDOWN = "text/markdown".replaceAll(/[a-z]/gu, (letter) => `[${letter}${letter.toUpperCase()}]`);
|
|
9
27
|
/** The variable that gives the function the time of the build, in milliseconds. */
|
|
10
28
|
const BUILT_AT = "APP_SERVER_BUILT_AT";
|
|
11
29
|
/** The function's file, next to the server entry. */
|
|
12
30
|
const FUNCTION_FILE = "vercel-function.js";
|
|
13
31
|
/** A path with `/` separators, as Vercel's config reads it. */
|
|
14
|
-
function posix(path) {
|
|
32
|
+
function posix$1(path) {
|
|
15
33
|
return path.split(sep).join("/");
|
|
16
34
|
}
|
|
17
35
|
/** A regular expression source that matches `text` as it is. */
|
|
@@ -40,11 +58,17 @@ function filesUnder(directory, under = "", parents = /* @__PURE__ */ new Set())
|
|
|
40
58
|
}
|
|
41
59
|
/**
|
|
42
60
|
* The `.vercel/output` routes: a CDN file gets its headers, and each other
|
|
43
|
-
* request goes to the function.
|
|
44
|
-
*
|
|
61
|
+
* request goes to the function. A file under `assetsPath` also gets the
|
|
62
|
+
* immutable cache. Why the `hit` phase: a CDN path with no file goes to the
|
|
63
|
+
* function, whose `no-store` 404 must not get the immutable cache.
|
|
45
64
|
*/
|
|
46
|
-
function routes(prefixes, cdnHeaders) {
|
|
65
|
+
function routes(prefixes, { assetsPath, cdnHeaders, pages }) {
|
|
47
66
|
return [
|
|
67
|
+
...pages.length === 0 ? [] : [{
|
|
68
|
+
src: `^${escaped(PAGES)}(?:/.*)?$`,
|
|
69
|
+
dest: "/index"
|
|
70
|
+
}],
|
|
71
|
+
...pages.flatMap((page) => pageRoutes(page)),
|
|
48
72
|
{ handle: "filesystem" },
|
|
49
73
|
{
|
|
50
74
|
src: "^/(.*)$",
|
|
@@ -53,7 +77,7 @@ function routes(prefixes, cdnHeaders) {
|
|
|
53
77
|
{ handle: "hit" },
|
|
54
78
|
...prefixes.map((prefix) => ({
|
|
55
79
|
src: `^${escaped(prefix)}.*$`,
|
|
56
|
-
headers: prefix ===
|
|
80
|
+
headers: prefix === assetsPath ? {
|
|
57
81
|
...cdnHeaders,
|
|
58
82
|
"Cache-Control": IMMUTABLE
|
|
59
83
|
} : cdnHeaders,
|
|
@@ -61,26 +85,160 @@ function routes(prefixes, cdnHeaders) {
|
|
|
61
85
|
}))
|
|
62
86
|
];
|
|
63
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* The routes of one page that the CDN serves: one for each case of the
|
|
90
|
+
* presence headers, with the headers of that case. Why only GET and HEAD: the
|
|
91
|
+
* function answers the other methods, such as a form's POST. Why the
|
|
92
|
+
* function for a request that names `text/markdown`: it negotiates the twin.
|
|
93
|
+
*/
|
|
94
|
+
function pageRoutes({ path, file, answers, twin }) {
|
|
95
|
+
const src = `^${escaped(path)}$`;
|
|
96
|
+
const names = [...new Set(answers.flatMap(({ present }) => present))];
|
|
97
|
+
return [...twin == null ? [] : [{
|
|
98
|
+
src,
|
|
99
|
+
has: [{
|
|
100
|
+
type: "header",
|
|
101
|
+
key: "accept",
|
|
102
|
+
value: { re: MARKDOWN }
|
|
103
|
+
}],
|
|
104
|
+
dest: "/index"
|
|
105
|
+
}], ...answers.map(({ present, headers }) => {
|
|
106
|
+
const missing = names.filter((name) => !present.includes(name));
|
|
107
|
+
return {
|
|
108
|
+
src,
|
|
109
|
+
caseSensitive: true,
|
|
110
|
+
methods: ["GET", "HEAD"],
|
|
111
|
+
...present.length === 0 ? {} : { has: present.map((key) => ({
|
|
112
|
+
type: "header",
|
|
113
|
+
key
|
|
114
|
+
})) },
|
|
115
|
+
...missing.length === 0 ? {} : { missing: missing.map((key) => ({
|
|
116
|
+
type: "header",
|
|
117
|
+
key
|
|
118
|
+
})) },
|
|
119
|
+
headers,
|
|
120
|
+
dest: `${PAGES}${file}`
|
|
121
|
+
};
|
|
122
|
+
})];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Whether `cdnPages` accepts `path`. Why both trailing-slash forms: with
|
|
126
|
+
* `trailingSlash: "always"`, the CDN serves `/blog/` for the prerendered
|
|
127
|
+
* path `/blog`.
|
|
128
|
+
*/
|
|
129
|
+
function accepts(cdnPages, path) {
|
|
130
|
+
return cdnPages(path) && (path === "/" || !path.endsWith("/") || cdnPages(path.slice(0, -1)));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Finds the pages that the CDN serves ({@link VercelOptions.cdnPages}), and
|
|
134
|
+
* writes their bodies under `static/`.
|
|
135
|
+
*/
|
|
136
|
+
function findCdnPages(entryFile, output, { cdnPages, routeBudget }) {
|
|
137
|
+
if (cdnPages === false) return {
|
|
138
|
+
cdn: [],
|
|
139
|
+
server: []
|
|
140
|
+
};
|
|
141
|
+
const pagesDirectory = join(output, "static", PAGES);
|
|
142
|
+
const reportFile = join(output, "pages.json");
|
|
143
|
+
try {
|
|
144
|
+
execFileSync(process.execPath, [
|
|
145
|
+
PAGES_SCRIPT,
|
|
146
|
+
entryFile,
|
|
147
|
+
pagesDirectory,
|
|
148
|
+
reportFile
|
|
149
|
+
], {
|
|
150
|
+
stdio: "inherit",
|
|
151
|
+
env: {
|
|
152
|
+
...process.env,
|
|
153
|
+
NODE_ENV: "production"
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw new Error("@ngrok/app-server/vercel could not start the server build to find the prerendered pages that the CDN can serve. Give the build the environment of the app, or remove `cdnPages`.", { cause: error });
|
|
158
|
+
}
|
|
159
|
+
const report = JSON.parse(readFileSync(reportFile, "utf8"));
|
|
160
|
+
rmSync(reportFile);
|
|
161
|
+
const pages = {
|
|
162
|
+
cdn: [],
|
|
163
|
+
server: [...report.server]
|
|
164
|
+
};
|
|
165
|
+
let routeCount = 0;
|
|
166
|
+
for (const page of report.cdn) {
|
|
167
|
+
const count = pageRoutes(page).length;
|
|
168
|
+
let reason;
|
|
169
|
+
if (cdnPages !== true && !accepts(cdnPages, page.path)) reason = "`cdnPages` keeps it in the function";
|
|
170
|
+
else if (page.answers.some(({ headers }) => Object.values(headers).some((value) => value.includes("$")))) reason = "a header has a `$`, which a Vercel route reads as a capture";
|
|
171
|
+
else if (routeCount + count > routeBudget) reason = `the CDN routes of the pages reach Vercel's limit of ${ROUTE_LIMIT} routes`;
|
|
172
|
+
if (reason == null) {
|
|
173
|
+
pages.cdn.push(page);
|
|
174
|
+
routeCount += count;
|
|
175
|
+
} else {
|
|
176
|
+
rmSync(join(pagesDirectory, page.file));
|
|
177
|
+
pages.server.push({
|
|
178
|
+
path: page.path,
|
|
179
|
+
reason
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return pages;
|
|
184
|
+
}
|
|
185
|
+
/** Writes the paths that the function serves, and why, so the build log shows them. */
|
|
186
|
+
function reportPages({ cdn, server }) {
|
|
187
|
+
const shown = server.slice(0, 20);
|
|
188
|
+
process.stdout.write([
|
|
189
|
+
`@ngrok/app-server/vercel: the CDN serves ${cdn.length} prerendered paths, and the function serves ${server.length}.`,
|
|
190
|
+
...shown.map(({ path, reason }) => ` ${path}: ${reason}`),
|
|
191
|
+
...server.length > shown.length ? [` and ${server.length - shown.length} more`] : [],
|
|
192
|
+
""
|
|
193
|
+
].join("\n"));
|
|
194
|
+
}
|
|
64
195
|
/** Writes `.vercel/output` (the Build Output API, version 3) for one build. */
|
|
65
|
-
function writeOutput({ root, clientDirectory, entryFile }, { cdnPaths = [], cdnHeaders = {}, regions, memory, maxDuration }) {
|
|
66
|
-
const prefixes = [
|
|
196
|
+
function writeOutput({ root, clientDirectory, entryFile, assetsPath }, { cdnPaths = [], cdnHeaders = {}, cdnPages = false, regions, memory, maxDuration }) {
|
|
197
|
+
const prefixes = [...cdnPaths.filter((path) => path !== assetsPath), assetsPath];
|
|
67
198
|
const output = join(root, ".vercel/output");
|
|
68
199
|
rmSync(output, {
|
|
69
200
|
recursive: true,
|
|
70
201
|
force: true
|
|
71
202
|
});
|
|
203
|
+
const pages = findCdnPages(entryFile, output, {
|
|
204
|
+
cdnPages,
|
|
205
|
+
routeBudget: ROUTE_LIMIT - routes(prefixes, {
|
|
206
|
+
assetsPath,
|
|
207
|
+
cdnHeaders,
|
|
208
|
+
pages: []
|
|
209
|
+
}).length - 1
|
|
210
|
+
});
|
|
211
|
+
if (cdnPages !== false) reportPages(pages);
|
|
72
212
|
const fromRoot = (path) => {
|
|
73
213
|
const inside = relative(root, path);
|
|
74
214
|
if (inside.startsWith("..") || isAbsolute(inside)) throw new Error(`@ngrok/app-server/vercel needs ${path} inside the Vite root ${root}.`);
|
|
75
215
|
return inside;
|
|
76
216
|
};
|
|
77
217
|
const functionDirectory = join(output, "functions/index.func");
|
|
78
|
-
const isCdnFile = (file) => prefixes.some((prefix) => `/${posix(file)}`.startsWith(prefix));
|
|
79
|
-
|
|
218
|
+
const isCdnFile = (file) => prefixes.some((prefix) => `/${posix$1(file)}`.startsWith(prefix));
|
|
219
|
+
const clientFiles = filesUnder(clientDirectory);
|
|
220
|
+
const listed = new Set(clientFiles);
|
|
221
|
+
/** The file of each brotli copy that the function keeps, with the size of the file. */
|
|
222
|
+
const brotliOnly = {};
|
|
223
|
+
/**
|
|
224
|
+
* Whether the function drops `file`, a file or a gzip copy, because the
|
|
225
|
+
* brotli copy of its file takes its place. Why: the function then holds one
|
|
226
|
+
* copy of each text file, not three. Each browser accepts brotli, and the
|
|
227
|
+
* CDN compresses the decompressed file for a client that does not.
|
|
228
|
+
*/
|
|
229
|
+
const brotliCopyOnly = (file) => {
|
|
230
|
+
const name = basename(file);
|
|
231
|
+
const original = name.startsWith(".") ? /^\.(?<name>.+)\.gz$/u.exec(name)?.groups?.name : name;
|
|
232
|
+
return original != null && listed.has(join(dirname(file), original)) && listed.has(join(dirname(file), copyName(original, "br")));
|
|
233
|
+
};
|
|
234
|
+
for (const file of clientFiles) {
|
|
80
235
|
const from = join(clientDirectory, file);
|
|
81
|
-
if (!isCdnFile(file))
|
|
82
|
-
|
|
236
|
+
if (!isCdnFile(file)) {
|
|
237
|
+
if (!brotliCopyOnly(file)) copyFile(from, join(functionDirectory, fromRoot(from)));
|
|
238
|
+
else if (!basename(file).startsWith(".")) brotliOnly[`/${posix$1(file)}`] = statSync(from).size;
|
|
239
|
+
} else if (!hasDotSegment(`/${posix$1(file)}`)) copyFile(from, join(output, "static", file));
|
|
83
240
|
}
|
|
241
|
+
if (Object.keys(brotliOnly).length > 0) writeFileSync(join(functionDirectory, fromRoot(clientDirectory), BROTLI_ONLY_LIST), JSON.stringify(brotliOnly));
|
|
84
242
|
const serverDirectory = dirname(entryFile);
|
|
85
243
|
const functionFile = join(serverDirectory, FUNCTION_FILE);
|
|
86
244
|
cpSync(serverDirectory, join(functionDirectory, fromRoot(serverDirectory)), {
|
|
@@ -95,7 +253,7 @@ function writeOutput({ root, clientDirectory, entryFile }, { cdnPaths = [], cdnH
|
|
|
95
253
|
].join("\n"));
|
|
96
254
|
writeFileSync(join(functionDirectory, ".vc-config.json"), `${JSON.stringify({
|
|
97
255
|
runtime: `nodejs${process.versions.node.split(".")[0]}.x`,
|
|
98
|
-
handler: posix(fromRoot(functionFile)),
|
|
256
|
+
handler: posix$1(fromRoot(functionFile)),
|
|
99
257
|
launcherType: "Nodejs",
|
|
100
258
|
supportsResponseStreaming: true,
|
|
101
259
|
environment: { [BUILT_AT]: String(Date.now()) },
|
|
@@ -105,7 +263,11 @@ function writeOutput({ root, clientDirectory, entryFile }, { cdnPaths = [], cdnH
|
|
|
105
263
|
}, null, " ")}\n`);
|
|
106
264
|
writeFileSync(join(output, "config.json"), `${JSON.stringify({
|
|
107
265
|
version: 3,
|
|
108
|
-
routes: routes(prefixes,
|
|
266
|
+
routes: routes(prefixes, {
|
|
267
|
+
assetsPath,
|
|
268
|
+
cdnHeaders,
|
|
269
|
+
pages: pages.cdn
|
|
270
|
+
})
|
|
109
271
|
}, null, " ")}\n`);
|
|
110
272
|
}
|
|
111
273
|
/** Throws for a CDN path that is not a URL path prefix, so the config fails, not the deploy. */
|
|
@@ -116,9 +278,10 @@ function checkCdnPaths(paths) {
|
|
|
116
278
|
* The build side of the vercel host. After the build, it writes
|
|
117
279
|
* `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:
|
|
118
280
|
*
|
|
119
|
-
* - `static/`: the files
|
|
120
|
-
* serves them, and each file
|
|
121
|
-
* cache.
|
|
281
|
+
* - `static/`: the files of Vite's `build.assetsDir` (`/assets/` by default)
|
|
282
|
+
* and the other `cdnPaths`. The CDN serves them, and each file of
|
|
283
|
+
* `build.assetsDir` gets a one-year immutable cache. It also holds the
|
|
284
|
+
* prerendered pages that the CDN serves, with `cdnPages`.
|
|
122
285
|
* - `functions/index.func/`: one Node.js function that runs the pipeline for
|
|
123
286
|
* each other request, with the whole server build and the rest of the
|
|
124
287
|
* client build.
|
package/dist/vercel-vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel-vite.js","names":[],"sources":["../src/vercel/vite.ts"],"sourcesContent":["import {\n\tcopyFileSync,\n\tcpSync,\n\tmkdirSync,\n\treaddirSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { basename, dirname, isAbsolute, join, relative, sep } from \"node:path\";\nimport { hasDotSegment } from \"../core/static-files.js\";\nimport type { HostBuild, HostOutput } from \"../vite/index.js\";\n\n/** Options for {@link vercel}. */\nexport type VercelOptions = {\n\t/**\n\t * More URL path prefixes of the client build that Vercel's CDN serves,\n\t * such as `[\"/blog-assets/\"]`. Each starts and ends with `/`. `/assets/`\n\t * is always one. Their files skip the pipeline, and the function does not\n\t * carry them.\n\t */\n\tcdnPaths?: readonly string[];\n\t/** Headers for each file that the CDN serves, such as CORS headers. */\n\tcdnHeaders?: Readonly<Record<string, string>>;\n\t/** The Vercel regions of the function, such as `[\"iad1\"]`. @default the project's */\n\tregions?: readonly string[];\n\t/** The memory of the function, in MB. @default the project's */\n\tmemory?: number;\n\t/** The longest time that a request runs, in seconds. @default the project's */\n\tmaxDuration?: number;\n};\n\n/** The hashed files of the client build. Their names change with their content. */\nconst ASSETS = \"/assets/\";\n\nconst IMMUTABLE = \"public, max-age=31536000, immutable\";\n\n/** The variable that gives the function the time of the build, in milliseconds. */\nconst BUILT_AT = \"APP_SERVER_BUILT_AT\";\n\n/** The function's file, next to the server entry. */\nconst FUNCTION_FILE = \"vercel-function.js\";\n\n/** A path with `/` separators, as Vercel's config reads it. */\nfunction posix(path: string): string {\n\treturn path.split(sep).join(\"/\");\n}\n\n/** A regular expression source that matches `text` as it is. */\nfunction escaped(text: string): string {\n\treturn text.replaceAll(/[$()*+.?[\\\\\\]^{|}]/gu, String.raw`\\$&`);\n}\n\n/** Copies the file at `from` to `to`, and makes the directories of `to`. */\nfunction copyFile(from: string, to: string): void {\n\tmkdirSync(dirname(to), { recursive: true });\n\tcopyFileSync(from, to);\n}\n\n/**\n * The path of each file under `directory`, relative to it. Why follow links:\n * the CDN and the function each get a copy of the linked file, not a link\n * whose target can be in the other part. Why the inodes of the parents: a\n * link to a parent directory must not make the walk endless.\n */\nfunction filesUnder(\n\tdirectory: string,\n\tunder = \"\",\n\tparents: ReadonlySet<string> = new Set(),\n): string[] {\n\tconst stats = statSync(join(directory, under), { throwIfNoEntry: false });\n\tif (stats == null) {\n\t\treturn [];\n\t}\n\tif (!stats.isDirectory()) {\n\t\treturn [under];\n\t}\n\tconst inode = `${stats.dev}:${stats.ino}`;\n\tif (parents.has(inode)) {\n\t\treturn [];\n\t}\n\tconst inside = new Set(parents).add(inode);\n\treturn readdirSync(join(directory, under)).flatMap((name) =>\n\t\tfilesUnder(directory, join(under, name), inside),\n\t);\n}\n\n/**\n * The `.vercel/output` routes: a CDN file gets its headers, and each other\n * request goes to the function. Why the `hit` phase: a CDN path with no file\n * goes to the function, whose `no-store` 404 must not get the immutable cache.\n */\nfunction routes(prefixes: readonly string[], cdnHeaders: Readonly<Record<string, string>>) {\n\treturn [\n\t\t{ handle: \"filesystem\" },\n\t\t{ src: \"^/(.*)$\", dest: \"/index\" },\n\t\t{ handle: \"hit\" },\n\t\t...prefixes.map((prefix) => ({\n\t\t\t// Why `.*$`: Vercel adds `$` to a pattern that has none.\n\t\t\tsrc: `^${escaped(prefix)}.*$`,\n\t\t\theaders: prefix === ASSETS ? { ...cdnHeaders, \"Cache-Control\": IMMUTABLE } : cdnHeaders,\n\t\t\tcontinue: true,\n\t\t})),\n\t];\n}\n\n/** Writes `.vercel/output` (the Build Output API, version 3) for one build. */\nfunction writeOutput(\n\t{ root, clientDirectory, entryFile }: HostOutput,\n\t{ cdnPaths = [], cdnHeaders = {}, regions, memory, maxDuration }: VercelOptions,\n): void {\n\tconst prefixes = [ASSETS, ...cdnPaths.filter((path) => path !== ASSETS)];\n\tconst output = join(root, \".vercel/output\");\n\trmSync(output, { recursive: true, force: true });\n\tconst fromRoot = (path: string): string => {\n\t\tconst inside = relative(root, path);\n\t\tif (inside.startsWith(\"..\") || isAbsolute(inside)) {\n\t\t\tthrow new Error(`@ngrok/app-server/vercel needs ${path} inside the Vite root ${root}.`);\n\t\t}\n\t\treturn inside;\n\t};\n\tconst functionDirectory = join(output, \"functions/index.func\");\n\tconst isCdnFile = (file: string): boolean =>\n\t\tprefixes.some((prefix) => `/${posix(file)}`.startsWith(prefix));\n\n\tfor (const file of filesUnder(clientDirectory)) {\n\t\tconst from = join(clientDirectory, file);\n\t\tif (!isCdnFile(file)) {\n\t\t\tcopyFile(from, join(functionDirectory, fromRoot(from)));\n\t\t} else if (!hasDotSegment(`/${posix(file)}`)) {\n\t\t\t// Why the static stages' check: the CDN sends each file that it has, and the static stages\n\t\t\t// send no dotfile, such as a compressed copy, and no file in a dot directory.\n\t\t\tcopyFile(from, join(output, \"static\", file));\n\t\t}\n\t}\n\n\t// Why the whole server build: it runs with no install, and it keeps the client build's path.\n\tconst serverDirectory = dirname(entryFile);\n\tconst functionFile = join(serverDirectory, FUNCTION_FILE);\n\tcpSync(serverDirectory, join(functionDirectory, fromRoot(serverDirectory)), {\n\t\trecursive: true,\n\t\t// Why: a link that keeps its target can point at the build machine.\n\t\tdereference: true,\n\t\t// Why: the client build can be inside the server build, and the loop above copied its part.\n\t\tfilter: (path) => path !== clientDirectory,\n\t});\n\twriteFileSync(\n\t\tjoin(functionDirectory, fromRoot(functionFile)),\n\t\t[\n\t\t\t`import { appServer, hostModule } from ${JSON.stringify(`./${basename(entryFile)}`)};`,\n\t\t\t`export default hostModule.handler(appServer);`,\n\t\t\t\"\",\n\t\t].join(\"\\n\"),\n\t);\n\twriteFileSync(\n\t\tjoin(functionDirectory, \".vc-config.json\"),\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\t// Why the build's Node.js: the server build targets the Node.js that built it.\n\t\t\t\truntime: `nodejs${process.versions.node.split(\".\")[0]}.x`,\n\t\t\t\thandler: posix(fromRoot(functionFile)),\n\t\t\t\tlauncherType: \"Nodejs\",\n\t\t\t\tsupportsResponseStreaming: true,\n\t\t\t\t// Why: the deploy gives each file of the function one fixed time, and the ETag of a file\n\t\t\t\t// reads its time. See `host` in `@ngrok/app-server/vercel`.\n\t\t\t\tenvironment: { [BUILT_AT]: String(Date.now()) },\n\t\t\t\t...(regions == null ? {} : { regions }),\n\t\t\t\t...(memory == null ? {} : { memory }),\n\t\t\t\t...(maxDuration == null ? {} : { maxDuration }),\n\t\t\t},\n\t\t\tnull,\n\t\t\t\"\\t\",\n\t\t)}\\n`,\n\t);\n\twriteFileSync(\n\t\tjoin(output, \"config.json\"),\n\t\t`${JSON.stringify({ version: 3, routes: routes(prefixes, cdnHeaders) }, null, \"\\t\")}\\n`,\n\t);\n}\n\n/** Throws for a CDN path that is not a URL path prefix, so the config fails, not the deploy. */\nfunction checkCdnPaths(paths: readonly string[]): void {\n\tfor (const path of paths) {\n\t\tif (!path.startsWith(\"/\") || !path.endsWith(\"/\") || path === \"/\" || path.includes(\"..\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Each cdnPaths entry is a URL path prefix that starts and ends with \"/\", such as \"/blog-assets/\", not ${JSON.stringify(path)}.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The build side of the vercel host. After the build, it writes\n * `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:\n *\n * - `static/`: the files under `/assets/` and the other `cdnPaths`. The CDN\n * serves them, and each file under `/assets/` gets a one-year immutable\n * cache.\n * - `functions/index.func/`: one Node.js function that runs the pipeline for\n * each other request, with the whole server build and the rest of the\n * client build.\n *\n * @example\n * appServer({ host: vercel() });\n */\nexport function vercel(options: VercelOptions = {}): HostBuild {\n\tcheckCdnPaths(options.cdnPaths ?? []);\n\treturn {\n\t\tname: \"vercel\",\n\t\truntimeModule: \"@ngrok/app-server/vercel\",\n\t\tentryFileName: \"app-server.js\",\n\t\toutput: (build) => {\n\t\t\twriteOutput(build, options);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAiCA,MAAM,SAAS;AAEf,MAAM,YAAY;;AAGlB,MAAM,WAAW;;AAGjB,MAAM,gBAAgB;;AAGtB,SAAS,MAAM,MAAsB;CACpC,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;AAChC;;AAGA,SAAS,QAAQ,MAAsB;CACtC,OAAO,KAAK,WAAW,wBAAwB,OAAO,GAAG,KAAK;AAC/D;;A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I,EAAE,OAAO;EACnC,GAAI,eAAe,OAAO,CAAC,IAAI,EAAE,YAAY;CAC9C,GACA,MACA,GACD,EAAE,GACH;CACA,cACC,KAAK,QAAQ,aAAa,GAC1B,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG,QAAQ,OAAO,UAAU,UAAU;CAAE,GAAG,MAAM,GAAI,EAAE,GACrF;AACD;;AAGA,SAAS,cAAc,OAAgC;CACtD,KAAK,MAAM,QAAQ,OAClB,IAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,OAAO,KAAK,SAAS,IAAI,GACrF,MAAM,IAAI,MACT,wGAAwG,KAAK,UAAU,IAAI,EAAE,EAC9H;AAGH;;;;;;;;;;;;;;;AAgBA,SAAgB,OAAO,UAAyB,CAAC,GAAc;CAC9D,cAAc,QAAQ,YAAY,CAAC,CAAC;CACpC,OAAO;EACN,MAAM;EACN,eAAe;EACf,eAAe;EACf,SAAS,UAAU;GAClB,YAAY,OAAO,OAAO;EAC3B;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"vercel-vite.js","names":["posix"],"sources":["../src/vercel/vite.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport {\n\tcopyFileSync,\n\tcpSync,\n\tmkdirSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { basename, dirname, isAbsolute, join, relative, sep } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { copyName } from \"../core/compression.js\";\nimport { hasDotSegment } from \"../core/static-files.js\";\nimport type { HostBuild, HostOutput } from \"../vite/index.js\";\nimport { BROTLI_ONLY_LIST } from \"./brotli-only.js\";\nimport type { CdnPageReport, PagesReport } from \"./pages.js\";\n\n/** Options for {@link vercel}. */\nexport type VercelOptions = {\n\t/**\n\t * More URL path prefixes of the client build that Vercel's CDN serves,\n\t * such as `[\"/blog-assets/\"]`. Each starts and ends with `/`. The URL path\n\t * of Vite's `build.assetsDir`, `/assets/` by default, is always one. Their\n\t * files skip the pipeline, and the function does not carry them.\n\t */\n\tcdnPaths?: readonly string[];\n\t/** Headers for each file under `cdnPaths` and Vite's `build.assetsDir`, such as CORS headers. */\n\tcdnHeaders?: Readonly<Record<string, string>>;\n\t/**\n\t * Which prerendered pages the CDN serves, with no function. With `true`,\n\t * `vercel()` starts the server build once after the build and sends each\n\t * prerendered path through the pipeline as an anonymous client. The CDN\n\t * serves a page when its answer is a public 200 from its file, and the\n\t * same for a second client with another host, address, query, cookie,\n\t * `Authorization`, language, and country. The CDN then sends the\n\t * pipeline's body and headers. The function serves each other page, and\n\t * the CDN never keeps its answer. A function keeps each path that it\n\t * refuses in either trailing-slash form in the function, such as a page\n\t * whose answer depends on one query key. Why off by default: the build\n\t * runs each plugin's `setup`, and a check that the build cannot see can\n\t * then reach the CDN.\n\t * @default false\n\t */\n\tcdnPages?: boolean | ((path: string) => boolean);\n\t/** The Vercel regions of the function, such as `[\"iad1\"]`. @default the project's */\n\tregions?: readonly string[];\n\t/** The memory of the function, in MB. @default the project's */\n\tmemory?: number;\n\t/**\n\t * The longest time that a request runs, in seconds. It applies to each\n\t * request, because one function serves each route. A route module's\n\t * `config` export does nothing. @default the project's\n\t */\n\tmaxDuration?: number;\n};\n\nconst IMMUTABLE = \"public, max-age=31536000, immutable\";\n\n/** The most routes of a deployment. See https://vercel.com/docs/limits. */\nconst ROUTE_LIMIT = 2048;\n\n/**\n * The URL path under `static/` of the bodies of the pages that the CDN\n * serves. A route sends a request for it to the function, so a page has one\n * URL.\n */\nconst PAGES = \"/_app-server/pages\";\n\n/**\n * The script that finds the pages that the CDN serves. Why the source in a\n * `.ts` module: the tests of this package run the source, and Node.js runs a\n * `.ts` file with no import of its own.\n */\nconst PAGES_SCRIPT = fileURLToPath(\n\tnew URL(import.meta.url.endsWith(\".ts\") ? \"./pages.ts\" : \"./vercel-pages.js\", import.meta.url),\n);\n\n/** A case-insensitive pattern for `text/markdown`, in the regular expression syntax of any engine. */\nconst MARKDOWN = \"text/markdown\".replaceAll(\n\t/[a-z]/gu,\n\t(letter) => `[${letter}${letter.toUpperCase()}]`,\n);\n\n/** The variable that gives the function the time of the build, in milliseconds. */\nconst BUILT_AT = \"APP_SERVER_BUILT_AT\";\n\n/** The function's file, next to the server entry. */\nconst FUNCTION_FILE = \"vercel-function.js\";\n\n/** A path with `/` separators, as Vercel's config reads it. */\nfunction posix(path: string): string {\n\treturn path.split(sep).join(\"/\");\n}\n\n/** A regular expression source that matches `text` as it is. */\nfunction escaped(text: string): string {\n\treturn text.replaceAll(/[$()*+.?[\\\\\\]^{|}]/gu, String.raw`\\$&`);\n}\n\n/** Copies the file at `from` to `to`, and makes the directories of `to`. */\nfunction copyFile(from: string, to: string): void {\n\tmkdirSync(dirname(to), { recursive: true });\n\tcopyFileSync(from, to);\n}\n\n/**\n * The path of each file under `directory`, relative to it. Why follow links:\n * the CDN and the function each get a copy of the linked file, not a link\n * whose target can be in the other part. Why the inodes of the parents: a\n * link to a parent directory must not make the walk endless.\n */\nfunction filesUnder(\n\tdirectory: string,\n\tunder = \"\",\n\tparents: ReadonlySet<string> = new Set(),\n): string[] {\n\tconst stats = statSync(join(directory, under), { throwIfNoEntry: false });\n\tif (stats == null) {\n\t\treturn [];\n\t}\n\tif (!stats.isDirectory()) {\n\t\treturn [under];\n\t}\n\tconst inode = `${stats.dev}:${stats.ino}`;\n\tif (parents.has(inode)) {\n\t\treturn [];\n\t}\n\tconst inside = new Set(parents).add(inode);\n\treturn readdirSync(join(directory, under)).flatMap((name) =>\n\t\tfilesUnder(directory, join(under, name), inside),\n\t);\n}\n\n/**\n * The `.vercel/output` routes: a CDN file gets its headers, and each other\n * request goes to the function. A file under `assetsPath` also gets the\n * immutable cache. Why the `hit` phase: a CDN path with no file goes to the\n * function, whose `no-store` 404 must not get the immutable cache.\n */\nfunction routes(\n\tprefixes: readonly string[],\n\t{\n\t\tassetsPath,\n\t\tcdnHeaders,\n\t\tpages,\n\t}: {\n\t\tassetsPath: string;\n\t\tcdnHeaders: Readonly<Record<string, string>>;\n\t\tpages: readonly CdnPageReport[];\n\t},\n) {\n\treturn [\n\t\t...(pages.length === 0 ? [] : [{ src: `^${escaped(PAGES)}(?:/.*)?$`, dest: \"/index\" }]),\n\t\t...pages.flatMap((page) => pageRoutes(page)),\n\t\t{ handle: \"filesystem\" },\n\t\t{ src: \"^/(.*)$\", dest: \"/index\" },\n\t\t{ handle: \"hit\" },\n\t\t...prefixes.map((prefix) => ({\n\t\t\t// Why `.*$`: Vercel adds `$` to a pattern that has none.\n\t\t\tsrc: `^${escaped(prefix)}.*$`,\n\t\t\theaders: prefix === assetsPath ? { ...cdnHeaders, \"Cache-Control\": IMMUTABLE } : cdnHeaders,\n\t\t\tcontinue: true,\n\t\t})),\n\t];\n}\n\n/**\n * The routes of one page that the CDN serves: one for each case of the\n * presence headers, with the headers of that case. Why only GET and HEAD: the\n * function answers the other methods, such as a form's POST. Why the\n * function for a request that names `text/markdown`: it negotiates the twin.\n */\nfunction pageRoutes({ path, file, answers, twin }: CdnPageReport) {\n\tconst src = `^${escaped(path)}$`;\n\tconst names = [...new Set(answers.flatMap(({ present }) => present))];\n\treturn [\n\t\t...(twin == null\n\t\t\t? []\n\t\t\t: [\n\t\t\t\t\t{\n\t\t\t\t\t\tsrc,\n\t\t\t\t\t\thas: [{ type: \"header\", key: \"accept\", value: { re: MARKDOWN } }],\n\t\t\t\t\t\tdest: \"/index\",\n\t\t\t\t\t},\n\t\t\t\t]),\n\t\t...answers.map(({ present, headers }) => {\n\t\t\tconst missing = names.filter((name) => !present.includes(name));\n\t\t\treturn {\n\t\t\t\tsrc,\n\t\t\t\tcaseSensitive: true,\n\t\t\t\tmethods: [\"GET\", \"HEAD\"],\n\t\t\t\t...(present.length === 0 ? {} : { has: present.map((key) => ({ type: \"header\", key })) }),\n\t\t\t\t...(missing.length === 0\n\t\t\t\t\t? {}\n\t\t\t\t\t: { missing: missing.map((key) => ({ type: \"header\", key })) }),\n\t\t\t\theaders,\n\t\t\t\tdest: `${PAGES}${file}`,\n\t\t\t};\n\t\t}),\n\t];\n}\n\n/**\n * Whether `cdnPages` accepts `path`. Why both trailing-slash forms: with\n * `trailingSlash: \"always\"`, the CDN serves `/blog/` for the prerendered\n * path `/blog`.\n */\nfunction accepts(cdnPages: (path: string) => boolean, path: string): boolean {\n\treturn cdnPages(path) && (path === \"/\" || !path.endsWith(\"/\") || cdnPages(path.slice(0, -1)));\n}\n\n/**\n * Finds the pages that the CDN serves ({@link VercelOptions.cdnPages}), and\n * writes their bodies under `static/`.\n */\nfunction findCdnPages(\n\tentryFile: string,\n\toutput: string,\n\t{\n\t\tcdnPages,\n\t\trouteBudget,\n\t}: { cdnPages: NonNullable<VercelOptions[\"cdnPages\"]>; routeBudget: number },\n): PagesReport {\n\tif (cdnPages === false) {\n\t\treturn { cdn: [], server: [] };\n\t}\n\tconst pagesDirectory = join(output, \"static\", PAGES);\n\tconst reportFile = join(output, \"pages.json\");\n\ttry {\n\t\texecFileSync(process.execPath, [PAGES_SCRIPT, entryFile, pagesDirectory, reportFile], {\n\t\t\tstdio: \"inherit\",\n\t\t\tenv: { ...process.env, NODE_ENV: \"production\" },\n\t\t});\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t\"@ngrok/app-server/vercel could not start the server build to find the prerendered pages that the CDN can serve. Give the build the environment of the app, or remove `cdnPages`.\",\n\t\t\t{ cause: error },\n\t\t);\n\t}\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the step of this package wrote the file.\n\tconst report = JSON.parse(readFileSync(reportFile, \"utf8\")) as PagesReport;\n\trmSync(reportFile);\n\tconst pages: PagesReport = { cdn: [], server: [...report.server] };\n\tlet routeCount = 0;\n\tfor (const page of report.cdn) {\n\t\tconst count = pageRoutes(page).length;\n\t\tlet reason: string | undefined;\n\t\tif (cdnPages !== true && !accepts(cdnPages, page.path)) {\n\t\t\treason = \"`cdnPages` keeps it in the function\";\n\t\t} else if (\n\t\t\tpage.answers.some(({ headers }) =>\n\t\t\t\tObject.values(headers).some((value) => value.includes(\"$\")),\n\t\t\t)\n\t\t) {\n\t\t\t// Why: Vercel reads `$1` or `$name` in a route's header as a capture of its `src`.\n\t\t\treason = \"a header has a `$`, which a Vercel route reads as a capture\";\n\t\t} else if (routeCount + count > routeBudget) {\n\t\t\treason = `the CDN routes of the pages reach Vercel's limit of ${ROUTE_LIMIT} routes`;\n\t\t}\n\t\tif (reason == null) {\n\t\t\tpages.cdn.push(page);\n\t\t\trouteCount += count;\n\t\t} else {\n\t\t\trmSync(join(pagesDirectory, page.file));\n\t\t\tpages.server.push({ path: page.path, reason });\n\t\t}\n\t}\n\treturn pages;\n}\n\n/** Writes the paths that the function serves, and why, so the build log shows them. */\nfunction reportPages({ cdn, server }: PagesReport): void {\n\tconst shown = server.slice(0, 20);\n\tprocess.stdout.write(\n\t\t[\n\t\t\t`@ngrok/app-server/vercel: the CDN serves ${cdn.length} prerendered paths, and the function serves ${server.length}.`,\n\t\t\t...shown.map(({ path, reason }) => ` ${path}: ${reason}`),\n\t\t\t...(server.length > shown.length ? [` and ${server.length - shown.length} more`] : []),\n\t\t\t\"\",\n\t\t].join(\"\\n\"),\n\t);\n}\n\n/** Writes `.vercel/output` (the Build Output API, version 3) for one build. */\nfunction writeOutput(\n\t{ root, clientDirectory, entryFile, assetsPath }: HostOutput,\n\t{ cdnPaths = [], cdnHeaders = {}, cdnPages = false, regions, memory, maxDuration }: VercelOptions,\n): void {\n\t// Why `assetsPath` last: Vercel applies each matched rule in order, so its immutable cache wins\n\t// over a `cdnHeaders` value for a `cdnPaths` entry that holds it.\n\tconst prefixes = [...cdnPaths.filter((path) => path !== assetsPath), assetsPath];\n\tconst output = join(root, \".vercel/output\");\n\trmSync(output, { recursive: true, force: true });\n\tconst pages = findCdnPages(entryFile, output, {\n\t\tcdnPages,\n\t\t// Why one less: the route that sends a request for a page's body to the function.\n\t\trouteBudget: ROUTE_LIMIT - routes(prefixes, { assetsPath, cdnHeaders, pages: [] }).length - 1,\n\t});\n\tif (cdnPages !== false) {\n\t\treportPages(pages);\n\t}\n\tconst fromRoot = (path: string): string => {\n\t\tconst inside = relative(root, path);\n\t\tif (inside.startsWith(\"..\") || isAbsolute(inside)) {\n\t\t\tthrow new Error(`@ngrok/app-server/vercel needs ${path} inside the Vite root ${root}.`);\n\t\t}\n\t\treturn inside;\n\t};\n\tconst functionDirectory = join(output, \"functions/index.func\");\n\tconst isCdnFile = (file: string): boolean =>\n\t\tprefixes.some((prefix) => `/${posix(file)}`.startsWith(prefix));\n\n\tconst clientFiles = filesUnder(clientDirectory);\n\tconst listed = new Set(clientFiles);\n\t/** The file of each brotli copy that the function keeps, with the size of the file. */\n\tconst brotliOnly: Record<string, number> = {};\n\t/**\n\t * Whether the function drops `file`, a file or a gzip copy, because the\n\t * brotli copy of its file takes its place. Why: the function then holds one\n\t * copy of each text file, not three. Each browser accepts brotli, and the\n\t * CDN compresses the decompressed file for a client that does not.\n\t */\n\tconst brotliCopyOnly = (file: string): boolean => {\n\t\tconst name = basename(file);\n\t\tconst original = name.startsWith(\".\") ? /^\\.(?<name>.+)\\.gz$/u.exec(name)?.groups?.name : name;\n\t\treturn (\n\t\t\toriginal != null &&\n\t\t\tlisted.has(join(dirname(file), original)) &&\n\t\t\tlisted.has(join(dirname(file), copyName(original, \"br\")))\n\t\t);\n\t};\n\tfor (const file of clientFiles) {\n\t\tconst from = join(clientDirectory, file);\n\t\t// Why the function keeps the file of a page that the CDN serves: a request that no page route\n\t\t// matches, such as the other trailing slash form, or a markdown request, reaches the function.\n\t\tif (!isCdnFile(file)) {\n\t\t\tif (!brotliCopyOnly(file)) {\n\t\t\t\tcopyFile(from, join(functionDirectory, fromRoot(from)));\n\t\t\t} else if (!basename(file).startsWith(\".\")) {\n\t\t\t\tbrotliOnly[`/${posix(file)}`] = statSync(from).size;\n\t\t\t}\n\t\t} else if (!hasDotSegment(`/${posix(file)}`)) {\n\t\t\t// Why the static stages' check: the CDN sends each file that it has, and the static stages\n\t\t\t// send no dotfile, such as a compressed copy, and no file in a dot directory.\n\t\t\tcopyFile(from, join(output, \"static\", file));\n\t\t}\n\t}\n\n\tif (Object.keys(brotliOnly).length > 0) {\n\t\twriteFileSync(\n\t\t\tjoin(functionDirectory, fromRoot(clientDirectory), BROTLI_ONLY_LIST),\n\t\t\tJSON.stringify(brotliOnly),\n\t\t);\n\t}\n\n\t// Why the whole server build: it runs with no install, and it keeps the client build's path.\n\tconst serverDirectory = dirname(entryFile);\n\tconst functionFile = join(serverDirectory, FUNCTION_FILE);\n\tcpSync(serverDirectory, join(functionDirectory, fromRoot(serverDirectory)), {\n\t\trecursive: true,\n\t\t// Why: a link that keeps its target can point at the build machine.\n\t\tdereference: true,\n\t\t// Why: the client build can be inside the server build, and the loop above copied its part.\n\t\tfilter: (path) => path !== clientDirectory,\n\t});\n\twriteFileSync(\n\t\tjoin(functionDirectory, fromRoot(functionFile)),\n\t\t[\n\t\t\t`import { appServer, hostModule } from ${JSON.stringify(`./${basename(entryFile)}`)};`,\n\t\t\t`export default hostModule.handler(appServer);`,\n\t\t\t\"\",\n\t\t].join(\"\\n\"),\n\t);\n\twriteFileSync(\n\t\tjoin(functionDirectory, \".vc-config.json\"),\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\t// Why the build's Node.js: the server build targets the Node.js that built it.\n\t\t\t\truntime: `nodejs${process.versions.node.split(\".\")[0]}.x`,\n\t\t\t\thandler: posix(fromRoot(functionFile)),\n\t\t\t\tlauncherType: \"Nodejs\",\n\t\t\t\tsupportsResponseStreaming: true,\n\t\t\t\t// Why: the deploy gives each file of the function one fixed time, and the ETag of a file\n\t\t\t\t// reads its time. See `host` in `@ngrok/app-server/vercel`.\n\t\t\t\tenvironment: { [BUILT_AT]: String(Date.now()) },\n\t\t\t\t...(regions == null ? {} : { regions }),\n\t\t\t\t...(memory == null ? {} : { memory }),\n\t\t\t\t...(maxDuration == null ? {} : { maxDuration }),\n\t\t\t},\n\t\t\tnull,\n\t\t\t\"\\t\",\n\t\t)}\\n`,\n\t);\n\twriteFileSync(\n\t\tjoin(output, \"config.json\"),\n\t\t`${JSON.stringify({ version: 3, routes: routes(prefixes, { assetsPath, cdnHeaders, pages: pages.cdn }) }, null, \"\\t\")}\\n`,\n\t);\n}\n\n/** Throws for a CDN path that is not a URL path prefix, so the config fails, not the deploy. */\nfunction checkCdnPaths(paths: readonly string[]): void {\n\tfor (const path of paths) {\n\t\tif (!path.startsWith(\"/\") || !path.endsWith(\"/\") || path === \"/\" || path.includes(\"..\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Each cdnPaths entry is a URL path prefix that starts and ends with \"/\", such as \"/blog-assets/\", not ${JSON.stringify(path)}.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The build side of the vercel host. After the build, it writes\n * `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:\n *\n * - `static/`: the files of Vite's `build.assetsDir` (`/assets/` by default)\n * and the other `cdnPaths`. The CDN serves them, and each file of\n * `build.assetsDir` gets a one-year immutable cache. It also holds the\n * prerendered pages that the CDN serves, with `cdnPages`.\n * - `functions/index.func/`: one Node.js function that runs the pipeline for\n * each other request, with the whole server build and the rest of the\n * client build.\n *\n * @example\n * appServer({ host: vercel() });\n */\nexport function vercel(options: VercelOptions = {}): HostBuild {\n\tcheckCdnPaths(options.cdnPaths ?? []);\n\treturn {\n\t\tname: \"vercel\",\n\t\truntimeModule: \"@ngrok/app-server/vercel\",\n\t\tentryFileName: \"app-server.js\",\n\t\toutput: (build) => {\n\t\t\twriteOutput(build, options);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;AA0DA,MAAM,YAAY;;AAGlB,MAAM,cAAc;;;;;;AAOpB,MAAM,QAAQ;;;;;;AAOd,MAAM,eAAe,cACpB,IAAI,IAAI,YAAY,IAAI,SAAS,KAAK,IAAI,eAAe,qBAAqB,YAAY,GAAG,CAC9F;;AAGA,MAAM,WAAW,gBAAgB,WAChC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GAAI,WAAW,OAAO,CAAC,IAAI,EAAE,QAAQ;EACrC,GAAI,UAAU,OAAO,CAAC,IAAI,EAAE,OAAO;EACnC,GAAI,eAAe,OAAO,CAAC,IAAI,EAAE,YAAY;CAC9C,GACA,MACA,GACD,EAAE,GACH;CACA,cACC,KAAK,QAAQ,aAAa,GAC1B,GAAG,KAAK,UAAU;EAAE,SAAS;EAAG,QAAQ,OAAO,UAAU;GAAE;GAAY;GAAY,OAAO,MAAM;EAAI,CAAC;CAAE,GAAG,MAAM,GAAI,EAAE,GACvH;AACD;;AAGA,SAAS,cAAc,OAAgC;CACtD,KAAK,MAAM,QAAQ,OAClB,IAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,GAAG,KAAK,SAAS,OAAO,KAAK,SAAS,IAAI,GACrF,MAAM,IAAI,MACT,wGAAwG,KAAK,UAAU,IAAI,EAAE,EAC9H;AAGH;;;;;;;;;;;;;;;;AAiBA,SAAgB,OAAO,UAAyB,CAAC,GAAc;CAC9D,cAAc,QAAQ,YAAY,CAAC,CAAC;CACpC,OAAO;EACN,MAAM;EACN,eAAe;EACf,eAAe;EACf,SAAS,UAAU;GAClB,YAAY,OAAO,OAAO;EAC3B;CACD;AACD"}
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { c as HostRuntime } from "./types-
|
|
2
|
-
import { t as AppServerEntry } from "./entry-
|
|
1
|
+
import { c as HostRuntime } from "./types-BKJxtIuj.js";
|
|
2
|
+
import { t as AppServerEntry } from "./entry-CNL4OsEn.js";
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
4
|
/**
|
|
5
5
|
* The vercel host: one Vercel Function on Node.js. It reads the client build
|
|
6
6
|
* from the function's files and keeps `requestContext()` in
|
|
7
7
|
* `AsyncLocalStorage`, as the node host does. It has no listeners and no
|
|
8
8
|
* lifecycle: Vercel starts and stops the function, and {@link handler} calls
|
|
9
|
-
* the entry's `fetch`.
|
|
9
|
+
* the entry's `fetch`. It reads a file that the function keeps only as a
|
|
10
|
+
* brotli copy through that copy (see `vercel()`).
|
|
10
11
|
*
|
|
11
12
|
* Why no gzip: Vercel's CDN compresses each response, with Brotli when the
|
|
12
13
|
* client accepts it.
|
package/dist/vercel.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { n as flushLogs } from "./log-BP6xXXZl.js";
|
|
2
|
-
import { i as withForwardedProto } from "./create-server-
|
|
3
|
-
import { t as host$1 } from "./node-
|
|
4
|
-
import { t as requestListener } from "./response-writer-
|
|
2
|
+
import { i as withForwardedProto } from "./create-server-BX2rH6-E.js";
|
|
3
|
+
import { t as host$1 } from "./node-B0AYf_IA.js";
|
|
4
|
+
import { t as requestListener } from "./response-writer-DzvUAz9x.js";
|
|
5
|
+
import { n as brotliOnlyFiles } from "./brotli-only-DrA29Ecw.js";
|
|
5
6
|
|
|
6
7
|
// src/vercel/index.ts
|
|
7
8
|
/**
|
|
@@ -29,7 +30,8 @@ function withModifiedTime(files, mtimeMs) {
|
|
|
29
30
|
* from the function's files and keeps `requestContext()` in
|
|
30
31
|
* `AsyncLocalStorage`, as the node host does. It has no listeners and no
|
|
31
32
|
* lifecycle: Vercel starts and stops the function, and {@link handler} calls
|
|
32
|
-
* the entry's `fetch`.
|
|
33
|
+
* the entry's `fetch`. It reads a file that the function keeps only as a
|
|
34
|
+
* brotli copy through that copy (see `vercel()`).
|
|
33
35
|
*
|
|
34
36
|
* Why no gzip: Vercel's CDN compresses each response, with Brotli when the
|
|
35
37
|
* client accepts it.
|
|
@@ -40,7 +42,7 @@ function withModifiedTime(files, mtimeMs) {
|
|
|
40
42
|
const host = {
|
|
41
43
|
name: "vercel",
|
|
42
44
|
files: (clientDirectory) => {
|
|
43
|
-
const files = host$1.files(clientDirectory);
|
|
45
|
+
const files = brotliOnlyFiles(host$1.files(clientDirectory));
|
|
44
46
|
const builtAt = Number(process.env.APP_SERVER_BUILT_AT);
|
|
45
47
|
return Number.isFinite(builtAt) ? withModifiedTime(files, builtAt) : files;
|
|
46
48
|
},
|
package/dist/vercel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel.js","names":["nodeHost"],"sources":["../src/vercel/index.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { withForwardedProto } from \"../core/create-server.js\";\nimport type { AppServerEntry } from \"../core/entry.js\";\nimport { flushLogs } from \"../core/log.js\";\nimport type { FileInfo, HostRuntime, StaticFiles } from \"../core/types.js\";\nimport { host as nodeHost } from \"../node/index.js\";\nimport { requestListener } from \"../node/response-writer.js\";\n\n/**\n * `files` that give each file and directory the modification time\n * `mtimeMs`. Why: the deploy gives each file of the function one fixed time,\n * so a file that changes and keeps its size would keep its ETag. `vercel()`\n * sets `APP_SERVER_BUILT_AT` to the time of the build.\n */\nfunction withModifiedTime(files: StaticFiles, mtimeMs: number): StaticFiles {\n\tconst { snapshot } = files;\n\treturn {\n\t\tstat: async (path) => {\n\t\t\tconst info: FileInfo | undefined = await files.stat(path);\n\t\t\treturn info == null ? undefined : { ...info, mtimeMs };\n\t\t},\n\t\topen: files.open,\n\t\t...(snapshot == null\n\t\t\t? {}\n\t\t\t: { snapshot: async () => withModifiedTime(await snapshot(), mtimeMs) }),\n\t};\n}\n\n/**\n * The vercel host: one Vercel Function on Node.js. It reads the client build\n * from the function's files and keeps `requestContext()` in\n * `AsyncLocalStorage`, as the node host does. It has no listeners and no\n * lifecycle: Vercel starts and stops the function, and {@link handler} calls\n * the entry's `fetch
|
|
1
|
+
{"version":3,"file":"vercel.js","names":["nodeHost"],"sources":["../src/vercel/index.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { withForwardedProto } from \"../core/create-server.js\";\nimport type { AppServerEntry } from \"../core/entry.js\";\nimport { flushLogs } from \"../core/log.js\";\nimport type { FileInfo, HostRuntime, StaticFiles } from \"../core/types.js\";\nimport { host as nodeHost } from \"../node/index.js\";\nimport { requestListener } from \"../node/response-writer.js\";\nimport { brotliOnlyFiles } from \"./brotli-only.js\";\n\n/**\n * `files` that give each file and directory the modification time\n * `mtimeMs`. Why: the deploy gives each file of the function one fixed time,\n * so a file that changes and keeps its size would keep its ETag. `vercel()`\n * sets `APP_SERVER_BUILT_AT` to the time of the build.\n */\nfunction withModifiedTime(files: StaticFiles, mtimeMs: number): StaticFiles {\n\tconst { snapshot } = files;\n\treturn {\n\t\tstat: async (path) => {\n\t\t\tconst info: FileInfo | undefined = await files.stat(path);\n\t\t\treturn info == null ? undefined : { ...info, mtimeMs };\n\t\t},\n\t\topen: files.open,\n\t\t...(snapshot == null\n\t\t\t? {}\n\t\t\t: { snapshot: async () => withModifiedTime(await snapshot(), mtimeMs) }),\n\t};\n}\n\n/**\n * The vercel host: one Vercel Function on Node.js. It reads the client build\n * from the function's files and keeps `requestContext()` in\n * `AsyncLocalStorage`, as the node host does. It has no listeners and no\n * lifecycle: Vercel starts and stops the function, and {@link handler} calls\n * the entry's `fetch`. It reads a file that the function keeps only as a\n * brotli copy through that copy (see `vercel()`).\n *\n * Why no gzip: Vercel's CDN compresses each response, with Brotli when the\n * client accepts it.\n *\n * @example\n * export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });\n */\nexport const host: HostRuntime = {\n\tname: \"vercel\",\n\tfiles: (clientDirectory) => {\n\t\tconst files = brotliOnlyFiles(nodeHost.files(clientDirectory));\n\t\tconst builtAt = Number(process.env.APP_SERVER_BUILT_AT);\n\t\treturn Number.isFinite(builtAt) ? withModifiedTime(files, builtAt) : files;\n\t},\n\t...(nodeHost.storage == null ? {} : { storage: nodeHost.storage }),\n};\n\n/**\n * The function handler for the entry of a server build. The function file\n * that `vercel()` writes exports it.\n *\n * - The scheme comes from `X-Forwarded-Proto`, and the client address from\n * `X-Real-IP`. Why trust them: Vercel sets both headers on each request,\n * and replaces a value that the client sends.\n * - The node response writer sends each response, as the node host's\n * listener does.\n * - The log lines of the request reach stdout before the handler returns.\n * Why: Vercel can freeze the function after the response, before the next\n * turn of the event loop writes them.\n *\n * @example\n * export default hostModule.handler(appServer);\n */\nexport function handler(\n\tentry: AppServerEntry,\n): (incoming: IncomingMessage, outgoing: ServerResponse) => Promise<void> {\n\tconst listener = requestListener(\n\t\tasync (request, bindings) => {\n\t\t\tconst realIp = bindings.incoming?.headers[\"x-real-ip\"];\n\t\t\treturn entry.fetch(withForwardedProto(request), {\n\t\t\t\t...bindings,\n\t\t\t\t...(typeof realIp === \"string\" ? { remoteAddress: realIp } : {}),\n\t\t\t});\n\t\t},\n\t\t{ trustForwardedProto: true },\n\t);\n\treturn async (incoming, outgoing) => {\n\t\ttry {\n\t\t\tawait listener(incoming, outgoing);\n\t\t\t// Why wait: the access log writes its line when the response closes, after the listener returns.\n\t\t\tif (!outgoing.closed) {\n\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\toutgoing.once(\"close\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t} finally {\n\t\t\tflushLogs();\n\t\t\t// Why wait: a full pipe keeps the rest of a write in a queue, and a frozen function does not send it.\n\t\t\tif (process.stdout.writableLength > 0) {\n\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\tprocess.stdout.write(\"\", resolve);\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAS,iBAAiB,OAAoB,SAA8B;CAC3E,MAAM,EAAE,aAAa;CACrB,OAAO;EACN,MAAM,OAAO,SAAS;GACrB,MAAM,OAA6B,MAAM,MAAM,KAAK,IAAI;GACxD,OAAO,QAAQ,OAAO,SAAY;IAAE,GAAG;IAAM;GAAQ;EACtD;EACA,MAAM,MAAM;EACZ,GAAI,YAAY,OACb,CAAC,IACD,EAAE,UAAU,YAAY,iBAAiB,MAAM,SAAS,GAAG,OAAO,EAAE;CACxE;AACD;;;;;;;;;;;;;;;AAgBA,MAAa,OAAoB;CAChC,MAAM;CACN,QAAQ,oBAA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