@ngrok/app-server 0.3.2 → 0.3.3
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 +51 -15
- 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 +2 -2
- package/dist/client-browser.js +1 -1
- package/dist/client.js +1 -1
- package/dist/{create-server-kzZWd_Lo.d.ts → create-server-D4-nVOVJ.d.ts} +50 -13
- package/dist/{create-server-D0De6R7Q.js → create-server-jMl2ltHD.js} +572 -522
- package/dist/create-server-jMl2ltHD.js.map +1 -0
- package/dist/{entry-DuGgSKeB.d.ts → entry-BPrgE_6K.d.ts} +39 -3
- package/dist/entry-D9H4LA9c.js +351 -0
- package/dist/entry-D9H4LA9c.js.map +1 -0
- package/dist/{index-Bo5G9LuQ.d.ts → index-Db7dspq6.d.ts} +6 -1
- package/dist/index.d.ts +5 -15
- package/dist/index.js +3 -3
- package/dist/{load-entry-Bodyd2Ok.js → load-entry-D7r0mjEp.js} +3 -3
- package/dist/{load-entry-Bodyd2Ok.js.map → load-entry-D7r0mjEp.js.map} +1 -1
- package/dist/node-vite.d.ts +1 -1
- package/dist/node.d.ts +1 -1
- 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/{serve-caOkS3o5.js → serve-E0hSGe6_.js} +2 -2
- package/dist/{serve-caOkS3o5.js.map → serve-E0hSGe6_.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-CifYPRq1.js} +33 -5
- package/dist/start-CifYPRq1.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +1 -1
- package/dist/tanstack-start.d.ts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +2 -2
- package/dist/{trailing-slash-BrymAEGv.d.ts → trailing-slash-CFSv_Gzx.d.ts} +2 -2
- package/dist/{types-CEvzAmcn.d.ts → types-j29vspx_.d.ts} +15 -1
- 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 +160 -17
- package/dist/vercel-vite.js.map +1 -1
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +1 -1
- package/dist/{vite-tTxVimP6.js → vite-BDREIgiH.js} +44 -19
- package/dist/vite-BDREIgiH.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
- package/dist/build-id-C6sYO9Yp.js.map +0 -1
- package/dist/build-manifest-UDNk81Ce.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/start-DREqYrZh.js.map +0 -1
- package/dist/vite-tTxVimP6.js.map +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { t as errorAttributes } from "./log-BP6xXXZl.js";
|
|
2
|
+
import { i as readBuildManifest, n as DEFAULT_ASSETS_PATH } from "./build-manifest-DBMWe3Lx.js";
|
|
3
|
+
import { p as abortShutdownSignal, r as serverInternals } from "./create-server-jMl2ltHD.js";
|
|
4
|
+
import { a as keptFiles } from "./static-files-Beju9riB.js";
|
|
5
|
+
|
|
6
|
+
// src/core/static-pages.ts
|
|
7
|
+
/** The headers that change with each request, such as the request ID. A CDN answer drops them. */
|
|
8
|
+
const PER_REQUEST = /* @__PURE__ */ new Set(["x-request-id", "date"]);
|
|
9
|
+
/** The headers that the CDN sets for each file itself. */
|
|
10
|
+
const CDN_OWN = /* @__PURE__ */ new Set([
|
|
11
|
+
"content-length",
|
|
12
|
+
"etag",
|
|
13
|
+
"last-modified",
|
|
14
|
+
"accept-ranges",
|
|
15
|
+
"transfer-encoding",
|
|
16
|
+
"connection",
|
|
17
|
+
"keep-alive"
|
|
18
|
+
]);
|
|
19
|
+
/** A browser's `Accept`. A browser never names `text/markdown`, so it gets the HTML. */
|
|
20
|
+
const BROWSER_ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
|
21
|
+
/**
|
|
22
|
+
* A URL path that a CDN route matches as it is. Why only these characters: a
|
|
23
|
+
* CDN can match a path before or after it decodes it, and these two forms
|
|
24
|
+
* are the same. Why a slash after each segment but the last: the match then
|
|
25
|
+
* takes linear time.
|
|
26
|
+
*/
|
|
27
|
+
const PLAIN_PATH = /^\/(?:[\w.~-]+\/)*[\w.~-]*$/u;
|
|
28
|
+
/** The most presence headers. Why: each one doubles the requests and the CDN routes. */
|
|
29
|
+
const MAX_PRESENCE_HEADERS = 3;
|
|
30
|
+
/**
|
|
31
|
+
* The two clients of each check. The first is an anonymous browser. The
|
|
32
|
+
* second differs in each value that a CDN route does not match on: the host,
|
|
33
|
+
* the address, the query, the value of a presence header, and the request
|
|
34
|
+
* headers that a plugin reads most often to choose an answer. Why a cookie
|
|
35
|
+
* and `Authorization`: a plugin that sends a signed-in visitor to another
|
|
36
|
+
* page must keep its pages on the server. Why the geo headers: Vercel adds
|
|
37
|
+
* them, and a plugin can redirect by country.
|
|
38
|
+
*/
|
|
39
|
+
const CLIENTS = [{
|
|
40
|
+
origin: "https://localhost",
|
|
41
|
+
query: "",
|
|
42
|
+
address: "203.0.113.1",
|
|
43
|
+
presentValue: "1",
|
|
44
|
+
headers: {
|
|
45
|
+
Accept: BROWSER_ACCEPT,
|
|
46
|
+
"User-Agent": "app-server-build"
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
origin: "https://app-server-check.example",
|
|
50
|
+
query: "?app-server-check=1",
|
|
51
|
+
address: "198.51.100.2",
|
|
52
|
+
presentValue: "2",
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
"Accept-Language": "de-DE",
|
|
56
|
+
Authorization: "Bearer app-server-check",
|
|
57
|
+
Cookie: "session=app-server-check",
|
|
58
|
+
Referer: "https://app-server-check.example/",
|
|
59
|
+
"User-Agent": "app-server-build-check",
|
|
60
|
+
"X-Vercel-IP-City": "Berlin",
|
|
61
|
+
"X-Vercel-IP-Country": "DE",
|
|
62
|
+
"X-Vercel-IP-Country-Region": "BE"
|
|
63
|
+
}
|
|
64
|
+
}];
|
|
65
|
+
/**
|
|
66
|
+
* The answer of the pipeline for `path`. The request has each of `presence`
|
|
67
|
+
* that is in `present`, and no other of `presence`.
|
|
68
|
+
*/
|
|
69
|
+
async function answer(fetch, path, { client, presence, present }) {
|
|
70
|
+
const headers = new Headers({
|
|
71
|
+
...client.headers,
|
|
72
|
+
Host: new URL(client.origin).host
|
|
73
|
+
});
|
|
74
|
+
for (const name of presence) if (present.includes(name)) headers.set(name, client.presentValue);
|
|
75
|
+
else headers.delete(name);
|
|
76
|
+
const request = new Request(`${client.origin}${path}${client.query}`, { headers });
|
|
77
|
+
let file;
|
|
78
|
+
const response = await fetch(request, {
|
|
79
|
+
remoteAddress: client.address,
|
|
80
|
+
onServedFile: (served) => {
|
|
81
|
+
file = served;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
if (file == null) await response.body?.cancel();
|
|
85
|
+
return {
|
|
86
|
+
status: response.status,
|
|
87
|
+
headers: response.headers,
|
|
88
|
+
body: file == null ? /* @__PURE__ */ new Uint8Array() : new Uint8Array(await response.arrayBuffer()),
|
|
89
|
+
file
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function sameBytes(first, second) {
|
|
93
|
+
return first.length === second.length && first.every((byte, index) => byte === second[index]);
|
|
94
|
+
}
|
|
95
|
+
/** The headers of `headers` that a CDN answer keeps, sorted by name. */
|
|
96
|
+
function keptHeaders(headers) {
|
|
97
|
+
return [...headers].filter(([name]) => !PER_REQUEST.has(name) && !CDN_OWN.has(name)).toSorted(([first], [second]) => first < second ? -1 : 1);
|
|
98
|
+
}
|
|
99
|
+
/** The path of the markdown twin in a `Link` header, if any. */
|
|
100
|
+
function twinIn(link) {
|
|
101
|
+
return /<(?<path>[^>]+)>;\s*rel="alternate";\s*type="text\/markdown"/u.exec(link ?? "")?.groups?.path;
|
|
102
|
+
}
|
|
103
|
+
/** Why a CDN cannot keep `first`, or `undefined` when it can. */
|
|
104
|
+
function uncacheable(first, allowedVary) {
|
|
105
|
+
if (first.status !== 200) return `the status is ${first.status}`;
|
|
106
|
+
if (first.file == null) return "the answer does not come from a prerendered file";
|
|
107
|
+
if (!PLAIN_PATH.test(first.file)) return "the file path has a character that a CDN route can match two ways";
|
|
108
|
+
if (first.headers.has("set-cookie")) return "the answer sets a cookie";
|
|
109
|
+
for (const [name, value] of first.headers) {
|
|
110
|
+
const blocked = /\b(?:private|no-store|no-cache)\b/iu.exec(value);
|
|
111
|
+
if (blocked != null && (name === "cache-control" || name.endsWith("cdn-cache-control"))) return `the ${name} header has ${blocked[0]}`;
|
|
112
|
+
}
|
|
113
|
+
if (first.headers.has("content-encoding")) return "the answer has a Content-Encoding";
|
|
114
|
+
const vary = (first.headers.get("vary") ?? "").split(",").map((name) => name.trim().toLowerCase()).find((name) => name !== "" && !allowedVary.has(name));
|
|
115
|
+
return vary == null ? void 0 : `the answer varies on ${vary}`;
|
|
116
|
+
}
|
|
117
|
+
/** Why `second` differs from `first`, or `undefined` when they match. */
|
|
118
|
+
function difference(first, second) {
|
|
119
|
+
if (first.status !== second.status || first.file !== second.file) return "the status or the file changes with the request";
|
|
120
|
+
const changed = [...new Set([...keptHeaders(first.headers), ...keptHeaders(second.headers)].map(([name]) => name))].find((name) => first.headers.get(name) !== second.headers.get(name));
|
|
121
|
+
if (changed != null) return `the ${changed} header changes with the request`;
|
|
122
|
+
return sameBytes(first.body, second.body) ? void 0 : "the body changes with the request";
|
|
123
|
+
}
|
|
124
|
+
/** Each subset of `names`, the empty one first. */
|
|
125
|
+
function subsets(names) {
|
|
126
|
+
const all = [[]];
|
|
127
|
+
for (const name of names) all.push(...all.map((subset) => [...subset, name]));
|
|
128
|
+
return all;
|
|
129
|
+
}
|
|
130
|
+
/** The CDN answer of one path, or the reason that the server must answer it. */
|
|
131
|
+
async function staticPage(fetch, path, presence) {
|
|
132
|
+
if (!PLAIN_PATH.test(path)) return {
|
|
133
|
+
path,
|
|
134
|
+
reason: "the path has a character that a CDN route can match two ways"
|
|
135
|
+
};
|
|
136
|
+
const probe = await answer(fetch, path, {
|
|
137
|
+
client: CLIENTS[0],
|
|
138
|
+
presence,
|
|
139
|
+
present: []
|
|
140
|
+
});
|
|
141
|
+
if (probe.status === 308 && probe.headers.get("location") === `${path}/`) return staticPage(fetch, `${path}/`, presence);
|
|
142
|
+
if (presence.length > MAX_PRESENCE_HEADERS) return {
|
|
143
|
+
path,
|
|
144
|
+
reason: `more than ${MAX_PRESENCE_HEADERS} presence headers`
|
|
145
|
+
};
|
|
146
|
+
const firstAnswer = async (present) => present.length === 0 ? probe : answer(fetch, path, {
|
|
147
|
+
client: CLIENTS[0],
|
|
148
|
+
presence,
|
|
149
|
+
present
|
|
150
|
+
});
|
|
151
|
+
const answers = [];
|
|
152
|
+
let base;
|
|
153
|
+
let twin;
|
|
154
|
+
for (const present of subsets(presence)) {
|
|
155
|
+
const [first, second] = [await firstAnswer(present), await answer(fetch, path, {
|
|
156
|
+
client: CLIENTS[1],
|
|
157
|
+
presence,
|
|
158
|
+
present
|
|
159
|
+
})];
|
|
160
|
+
const caseTwin = twinIn(first.headers.get("link"));
|
|
161
|
+
const reason = uncacheable(first, /* @__PURE__ */ new Set([
|
|
162
|
+
"accept-encoding",
|
|
163
|
+
...presence,
|
|
164
|
+
...caseTwin == null ? [] : ["accept"]
|
|
165
|
+
])) ?? difference(first, second);
|
|
166
|
+
if (reason != null) return {
|
|
167
|
+
path,
|
|
168
|
+
reason
|
|
169
|
+
};
|
|
170
|
+
if (base != null && (base.file !== first.file || !sameBytes(base.body, first.body))) return {
|
|
171
|
+
path,
|
|
172
|
+
reason: "the body changes with a presence header"
|
|
173
|
+
};
|
|
174
|
+
if (base != null && caseTwin !== twin) return {
|
|
175
|
+
path,
|
|
176
|
+
reason: "the markdown twin changes with a presence header"
|
|
177
|
+
};
|
|
178
|
+
base ??= first;
|
|
179
|
+
twin = caseTwin;
|
|
180
|
+
answers.push({
|
|
181
|
+
present,
|
|
182
|
+
headers: Object.fromEntries(keptHeaders(first.headers))
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (base?.file == null) return {
|
|
186
|
+
path,
|
|
187
|
+
reason: "the answer does not come from a prerendered file"
|
|
188
|
+
};
|
|
189
|
+
if (twin != null && !PLAIN_PATH.test(twin)) return {
|
|
190
|
+
path,
|
|
191
|
+
reason: "the twin path has a character that a CDN route can match two ways"
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
path,
|
|
195
|
+
cdn: {
|
|
196
|
+
file: base.file,
|
|
197
|
+
body: base.body,
|
|
198
|
+
answers,
|
|
199
|
+
...twin == null ? {} : { twin }
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Sends each prerendered path through the pipeline, and gives the paths that
|
|
205
|
+
* a CDN can serve with no server. A path qualifies when its answer:
|
|
206
|
+
*
|
|
207
|
+
* - is a 200 from a prerendered file, with no cookie and no `private`,
|
|
208
|
+
* `no-store`, or `no-cache`
|
|
209
|
+
* - is the same, except for the request ID, for a second client with another
|
|
210
|
+
* host, client address, query, and value of each presence header, and with
|
|
211
|
+
* a cookie, `Authorization`, `Accept-Language`, and geo headers. Why: a CDN
|
|
212
|
+
* route matches only the path, a markdown `Accept`, and the presence of
|
|
213
|
+
* each presence header.
|
|
214
|
+
* - varies only on `Accept-Encoding`, on `Accept` for a markdown twin, and on
|
|
215
|
+
* the presence headers. Each case of the presence headers gets its own
|
|
216
|
+
* headers, and all cases must send the same body.
|
|
217
|
+
*
|
|
218
|
+
* An auth check that refuses an anonymous request keeps its pages on the
|
|
219
|
+
* server. Why: the first client sends no cookie and no `Authorization`.
|
|
220
|
+
*
|
|
221
|
+
* @yields Each path with its CDN answer, or with the reason that the server must answer it, in the order of `paths`.
|
|
222
|
+
* @example
|
|
223
|
+
* for await (const page of staticPages(fetch, ["/", "/about"], { presence: ["x-ngrok-edge"] })) {
|
|
224
|
+
* console.log(page.path, "cdn" in page ? "CDN" : page.reason);
|
|
225
|
+
* }
|
|
226
|
+
*/
|
|
227
|
+
async function* staticPages(fetch, paths, { presence }) {
|
|
228
|
+
for (const path of paths) yield await staticPage(fetch, path, presence);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// src/core/entry.ts
|
|
232
|
+
/** The version of the contract between the CLI and the `appServer` export of a build. */
|
|
233
|
+
const ENTRY_PROTOCOL = 2;
|
|
234
|
+
/**
|
|
235
|
+
* The `appServer` export of a server build: an app from `createServer`, the
|
|
236
|
+
* host, and the framework adapter for each mode. The `appServer` Vite plugin
|
|
237
|
+
* generates this export. Call this for a build without the plugin.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
|
|
241
|
+
*/
|
|
242
|
+
function createEntry({ app, host, framework, clientDirectory }) {
|
|
243
|
+
const internals = serverInternals(app);
|
|
244
|
+
if (internals == null) throw new Error("The app is not from `createServer()` of the copy of @ngrok/app-server in this build.");
|
|
245
|
+
internals.setRequestStore(host.storage);
|
|
246
|
+
const setupInfo = async (runtime) => {
|
|
247
|
+
const directory = clientDirectory ?? runtime.clientDirectory;
|
|
248
|
+
if (directory == null) throw new Error(`Give createEntry a clientDirectory: the ${runtime.name} adapter does not know the client build.`);
|
|
249
|
+
return {
|
|
250
|
+
files: host.files(directory),
|
|
251
|
+
isDataRequest: runtime.isDataRequest ?? (() => false),
|
|
252
|
+
contentTypes: runtime.contentTypes ?? {},
|
|
253
|
+
gzip: host.gzip,
|
|
254
|
+
logger: internals.logger
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
let prerenderedPaths = [];
|
|
258
|
+
/** Runs each plugin's `setup` for production, and gives the framework's run side. */
|
|
259
|
+
const prepareProduction = async () => {
|
|
260
|
+
const runtime = framework("production");
|
|
261
|
+
const shared = await setupInfo(runtime);
|
|
262
|
+
const snapshot = await shared.files.snapshot?.();
|
|
263
|
+
const files = snapshot == null ? shared.files : keptFiles(snapshot);
|
|
264
|
+
const manifest = await readBuildManifest(files);
|
|
265
|
+
const info = {
|
|
266
|
+
...shared,
|
|
267
|
+
files,
|
|
268
|
+
mode: "production",
|
|
269
|
+
prerenderedPaths: runtime.prerenderedPaths ?? manifest.prerendered,
|
|
270
|
+
capturedHeaders: new Map(Object.entries(manifest.headers)),
|
|
271
|
+
scriptHashes: new Map(Object.entries(manifest.scriptHashes)),
|
|
272
|
+
buildId: manifest.buildId,
|
|
273
|
+
assetsPath: manifest.assetsPath ?? "/assets/"
|
|
274
|
+
};
|
|
275
|
+
await internals.prepare(info);
|
|
276
|
+
({prerenderedPaths} = info);
|
|
277
|
+
return runtime;
|
|
278
|
+
};
|
|
279
|
+
let preparing;
|
|
280
|
+
/**
|
|
281
|
+
* The production run side, set up once. Why forget a failure: a serverless
|
|
282
|
+
* instance stays up, so the next request runs each `setup` again.
|
|
283
|
+
*/
|
|
284
|
+
const production = async () => {
|
|
285
|
+
preparing ??= prepareProduction().catch((error) => {
|
|
286
|
+
preparing = void 0;
|
|
287
|
+
throw error;
|
|
288
|
+
});
|
|
289
|
+
return preparing;
|
|
290
|
+
};
|
|
291
|
+
let development;
|
|
292
|
+
return {
|
|
293
|
+
protocol: 2,
|
|
294
|
+
app,
|
|
295
|
+
start: async () => {
|
|
296
|
+
const runtime = await production();
|
|
297
|
+
const server = await internals.listen(runtime, host.listeners?.());
|
|
298
|
+
host.lifecycle?.onStop(async () => server.shutdown().catch((error) => {
|
|
299
|
+
internals.logger.log("error", "shutdown failed", errorAttributes(error));
|
|
300
|
+
throw error;
|
|
301
|
+
}));
|
|
302
|
+
},
|
|
303
|
+
fetch: async (request, bindings) => {
|
|
304
|
+
const runtime = await production().catch((error) => {
|
|
305
|
+
internals.logger.log("error", "setup failed", errorAttributes(error));
|
|
306
|
+
throw error;
|
|
307
|
+
});
|
|
308
|
+
return app.fetch(request, {
|
|
309
|
+
...bindings,
|
|
310
|
+
framework: runtime
|
|
311
|
+
});
|
|
312
|
+
},
|
|
313
|
+
fetchDev: async (request, bindings, devServer) => {
|
|
314
|
+
development ??= framework("development");
|
|
315
|
+
await internals.prepare({
|
|
316
|
+
...await setupInfo(development),
|
|
317
|
+
mode: "development",
|
|
318
|
+
devServer,
|
|
319
|
+
prerenderedPaths: development.prerenderedPaths,
|
|
320
|
+
capturedHeaders: /* @__PURE__ */ new Map(),
|
|
321
|
+
scriptHashes: /* @__PURE__ */ new Map(),
|
|
322
|
+
buildId: void 0
|
|
323
|
+
});
|
|
324
|
+
return app.fetch(request, {
|
|
325
|
+
...bindings,
|
|
326
|
+
framework: development
|
|
327
|
+
});
|
|
328
|
+
},
|
|
329
|
+
async *staticPages() {
|
|
330
|
+
const runtime = await production();
|
|
331
|
+
yield* staticPages(async (request, bindings) => app.fetch(request, {
|
|
332
|
+
...bindings,
|
|
333
|
+
framework: runtime
|
|
334
|
+
}), prerenderedPaths, { presence: internals.presenceHeaders });
|
|
335
|
+
},
|
|
336
|
+
stopPlugins: internals.stopPlugins,
|
|
337
|
+
abortShutdownSignal
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Whether a value is an entry of this protocol version.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* isAppServerEntry((await import("./build/server/app-server.js")).appServer); // => true
|
|
345
|
+
*/
|
|
346
|
+
function isAppServerEntry(value) {
|
|
347
|
+
return typeof value === "object" && value != null && "protocol" in value && value.protocol === 2;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { isAppServerEntry as n, createEntry as t };
|
|
351
|
+
//# sourceMappingURL=entry-D9H4LA9c.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-D9H4LA9c.js","names":[],"sources":["../src/core/static-pages.ts","../src/core/entry.ts"],"sourcesContent":["/** What a content delivery network (CDN) sends for a prerendered path that it can serve with no server. */\nexport type CdnPage = {\n\t/** The URL path of the client build's file that the answer comes from, such as `/about/index.html`. */\n\tfile: string;\n\t/** The body that the pipeline sent. It can differ from the file, such as with `runtimeEnv` values. */\n\tbody: Uint8Array;\n\t/**\n\t * The response headers for each case of the presence headers. `present`\n\t * lists the headers that the request has. With no presence headers, there\n\t * is one case.\n\t */\n\tanswers: { present: readonly string[]; headers: Readonly<Record<string, string>> }[];\n\t/**\n\t * The path of the page's markdown twin. A request whose `Accept` names\n\t * `text/markdown` must reach the server, which negotiates the answer.\n\t */\n\ttwin?: string;\n};\n\n/** A prerendered path, with its CDN answer, or with the reason that the server must answer it. */\nexport type StaticPage = { path: string } & ({ cdn: CdnPage } | { reason: string });\n\n/**\n * Sends a request through the pipeline as a client at `remoteAddress`. The\n * pipeline calls `onServedFile` with the URL path of the client build's file\n * that `prerendered()` sends, if it sends one.\n */\nexport type PipelineFetch = (\n\trequest: Request,\n\tbindings: { remoteAddress: string; onServedFile: (path: string) => void },\n) => Promise<Response>;\n\n/** The headers that change with each request, such as the request ID. A CDN answer drops them. */\nconst PER_REQUEST = new Set([\"x-request-id\", \"date\"]);\n\n/** The headers that the CDN sets for each file itself. */\nconst CDN_OWN = new Set([\n\t\"content-length\",\n\t\"etag\",\n\t\"last-modified\",\n\t\"accept-ranges\",\n\t\"transfer-encoding\",\n\t\"connection\",\n\t\"keep-alive\",\n]);\n\n/** A browser's `Accept`. A browser never names `text/markdown`, so it gets the HTML. */\nconst BROWSER_ACCEPT = \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\";\n\n/**\n * A URL path that a CDN route matches as it is. Why only these characters: a\n * CDN can match a path before or after it decodes it, and these two forms\n * are the same. Why a slash after each segment but the last: the match then\n * takes linear time.\n */\nconst PLAIN_PATH = /^\\/(?:[\\w.~-]+\\/)*[\\w.~-]*$/u;\n\n/** The most presence headers. Why: each one doubles the requests and the CDN routes. */\nconst MAX_PRESENCE_HEADERS = 3;\n\n/** One answer of the pipeline. */\ntype Answer = {\n\tstatus: number;\n\theaders: Headers;\n\tbody: Uint8Array;\n\tfile: string | undefined;\n};\n\n/**\n * The two clients of each check. The first is an anonymous browser. The\n * second differs in each value that a CDN route does not match on: the host,\n * the address, the query, the value of a presence header, and the request\n * headers that a plugin reads most often to choose an answer. Why a cookie\n * and `Authorization`: a plugin that sends a signed-in visitor to another\n * page must keep its pages on the server. Why the geo headers: Vercel adds\n * them, and a plugin can redirect by country.\n */\nconst CLIENTS = [\n\t{\n\t\torigin: \"https://localhost\",\n\t\tquery: \"\",\n\t\taddress: \"203.0.113.1\",\n\t\tpresentValue: \"1\",\n\t\theaders: { Accept: BROWSER_ACCEPT, \"User-Agent\": \"app-server-build\" },\n\t},\n\t{\n\t\torigin: \"https://app-server-check.example\",\n\t\tquery: \"?app-server-check=1\",\n\t\taddress: \"198.51.100.2\",\n\t\tpresentValue: \"2\",\n\t\theaders: {\n\t\t\tAccept: \"application/json\",\n\t\t\t\"Accept-Language\": \"de-DE\",\n\t\t\tAuthorization: \"Bearer app-server-check\",\n\t\t\tCookie: \"session=app-server-check\",\n\t\t\tReferer: \"https://app-server-check.example/\",\n\t\t\t\"User-Agent\": \"app-server-build-check\",\n\t\t\t\"X-Vercel-IP-City\": \"Berlin\",\n\t\t\t\"X-Vercel-IP-Country\": \"DE\",\n\t\t\t\"X-Vercel-IP-Country-Region\": \"BE\",\n\t\t},\n\t},\n] as const;\n\n/**\n * The answer of the pipeline for `path`. The request has each of `presence`\n * that is in `present`, and no other of `presence`.\n */\nasync function answer(\n\tfetch: PipelineFetch,\n\tpath: string,\n\t{\n\t\tclient,\n\t\tpresence,\n\t\tpresent,\n\t}: {\n\t\tclient: (typeof CLIENTS)[number];\n\t\tpresence: readonly string[];\n\t\tpresent: readonly string[];\n\t},\n): Promise<Answer> {\n\t// Why `Host`: a listener gives it to each request, and a plugin can read it.\n\tconst headers = new Headers({ ...client.headers, Host: new URL(client.origin).host });\n\tfor (const name of presence) {\n\t\tif (present.includes(name)) {\n\t\t\theaders.set(name, client.presentValue);\n\t\t} else {\n\t\t\theaders.delete(name);\n\t\t}\n\t}\n\tconst request = new Request(`${client.origin}${path}${client.query}`, { headers });\n\tlet file: string | undefined;\n\tconst response = await fetch(request, {\n\t\tremoteAddress: client.address,\n\t\tonServedFile: (served) => {\n\t\t\tfile = served;\n\t\t},\n\t});\n\tif (file == null) {\n\t\t// Why cancel: only the answer of a file can go on a CDN, and another body can stream with no end.\n\t\tawait response.body?.cancel();\n\t}\n\treturn {\n\t\tstatus: response.status,\n\t\theaders: response.headers,\n\t\tbody: file == null ? new Uint8Array() : new Uint8Array(await response.arrayBuffer()),\n\t\tfile,\n\t};\n}\n\nfunction sameBytes(first: Uint8Array, second: Uint8Array): boolean {\n\treturn first.length === second.length && first.every((byte, index) => byte === second[index]);\n}\n\n/** The headers of `headers` that a CDN answer keeps, sorted by name. */\nfunction keptHeaders(headers: Headers): [string, string][] {\n\treturn [...headers]\n\t\t.filter(([name]) => !PER_REQUEST.has(name) && !CDN_OWN.has(name))\n\t\t.toSorted(([first], [second]) => (first < second ? -1 : 1));\n}\n\n/** The path of the markdown twin in a `Link` header, if any. */\nfunction twinIn(link: string | null): string | undefined {\n\treturn /<(?<path>[^>]+)>;\\s*rel=\"alternate\";\\s*type=\"text\\/markdown\"/u.exec(link ?? \"\")?.groups\n\t\t?.path;\n}\n\n/** Why a CDN cannot keep `first`, or `undefined` when it can. */\nfunction uncacheable(first: Answer, allowedVary: ReadonlySet<string>): string | undefined {\n\tif (first.status !== 200) {\n\t\treturn `the status is ${first.status}`;\n\t}\n\tif (first.file == null) {\n\t\treturn \"the answer does not come from a prerendered file\";\n\t}\n\tif (!PLAIN_PATH.test(first.file)) {\n\t\treturn \"the file path has a character that a CDN route can match two ways\";\n\t}\n\tif (first.headers.has(\"set-cookie\")) {\n\t\treturn \"the answer sets a cookie\";\n\t}\n\t// Why each `CDN-Cache-Control` field: a CDN obeys it before `Cache-Control` (RFC 9213).\n\tfor (const [name, value] of first.headers) {\n\t\t// Why `i`: cache directives are case-insensitive.\n\t\tconst blocked = /\\b(?:private|no-store|no-cache)\\b/iu.exec(value);\n\t\tif (blocked != null && (name === \"cache-control\" || name.endsWith(\"cdn-cache-control\"))) {\n\t\t\treturn `the ${name} header has ${blocked[0]}`;\n\t\t}\n\t}\n\tif (first.headers.has(\"content-encoding\")) {\n\t\treturn \"the answer has a Content-Encoding\";\n\t}\n\tconst vary = (first.headers.get(\"vary\") ?? \"\")\n\t\t.split(\",\")\n\t\t.map((name) => name.trim().toLowerCase())\n\t\t.find((name) => name !== \"\" && !allowedVary.has(name));\n\treturn vary == null ? undefined : `the answer varies on ${vary}`;\n}\n\n/** Why `second` differs from `first`, or `undefined` when they match. */\nfunction difference(first: Answer, second: Answer): string | undefined {\n\tif (first.status !== second.status || first.file !== second.file) {\n\t\treturn \"the status or the file changes with the request\";\n\t}\n\tconst names = new Set(\n\t\t[...keptHeaders(first.headers), ...keptHeaders(second.headers)].map(([name]) => name),\n\t);\n\tconst changed = [...names].find((name) => first.headers.get(name) !== second.headers.get(name));\n\tif (changed != null) {\n\t\treturn `the ${changed} header changes with the request`;\n\t}\n\treturn sameBytes(first.body, second.body) ? undefined : \"the body changes with the request\";\n}\n\n/** Each subset of `names`, the empty one first. */\nfunction subsets(names: readonly string[]): string[][] {\n\tconst all: string[][] = [[]];\n\tfor (const name of names) {\n\t\tall.push(...all.map((subset) => [...subset, name]));\n\t}\n\treturn all;\n}\n\n/** The CDN answer of one path, or the reason that the server must answer it. */\nasync function staticPage(\n\tfetch: PipelineFetch,\n\tpath: string,\n\tpresence: readonly string[],\n): Promise<StaticPage> {\n\tif (!PLAIN_PATH.test(path)) {\n\t\treturn { path, reason: \"the path has a character that a CDN route can match two ways\" };\n\t}\n\t// Why: the build records a path with no trailing slash, and `trailingSlash: \"always\"` sends it on.\n\tconst probe = await answer(fetch, path, { client: CLIENTS[0], presence, present: [] });\n\tif (probe.status === 308 && probe.headers.get(\"location\") === `${path}/`) {\n\t\treturn staticPage(fetch, `${path}/`, presence);\n\t}\n\tif (presence.length > MAX_PRESENCE_HEADERS) {\n\t\treturn { path, reason: `more than ${MAX_PRESENCE_HEADERS} presence headers` };\n\t}\n\t// Why reuse the probe: it is the first client's answer with no presence header.\n\tconst firstAnswer = async (present: readonly string[]): Promise<Answer> =>\n\t\tpresent.length === 0 ? probe : answer(fetch, path, { client: CLIENTS[0], presence, present });\n\tconst answers: CdnPage[\"answers\"] = [];\n\tlet base: Answer | undefined;\n\tlet twin: string | undefined;\n\tfor (const present of subsets(presence)) {\n\t\tconst [first, second] = [\n\t\t\tawait firstAnswer(present),\n\t\t\tawait answer(fetch, path, { client: CLIENTS[1], presence, present }),\n\t\t];\n\t\tconst caseTwin = twinIn(first.headers.get(\"link\"));\n\t\tconst allowedVary = new Set([\n\t\t\t\"accept-encoding\",\n\t\t\t...presence,\n\t\t\t...(caseTwin == null ? [] : [\"accept\"]),\n\t\t]);\n\t\tconst reason = uncacheable(first, allowedVary) ?? difference(first, second);\n\t\tif (reason != null) {\n\t\t\treturn { path, reason };\n\t\t}\n\t\tif (base != null && (base.file !== first.file || !sameBytes(base.body, first.body))) {\n\t\t\treturn { path, reason: \"the body changes with a presence header\" };\n\t\t}\n\t\t// Why: the CDN routes send each markdown request of a page to the server, or none.\n\t\tif (base != null && caseTwin !== twin) {\n\t\t\treturn { path, reason: \"the markdown twin changes with a presence header\" };\n\t\t}\n\t\tbase ??= first;\n\t\ttwin = caseTwin;\n\t\tanswers.push({ present, headers: Object.fromEntries(keptHeaders(first.headers)) });\n\t}\n\tif (base?.file == null) {\n\t\treturn { path, reason: \"the answer does not come from a prerendered file\" };\n\t}\n\tif (twin != null && !PLAIN_PATH.test(twin)) {\n\t\treturn { path, reason: \"the twin path has a character that a CDN route can match two ways\" };\n\t}\n\treturn {\n\t\tpath,\n\t\tcdn: { file: base.file, body: base.body, answers, ...(twin == null ? {} : { twin }) },\n\t};\n}\n\n/**\n * Sends each prerendered path through the pipeline, and gives the paths that\n * a CDN can serve with no server. A path qualifies when its answer:\n *\n * - is a 200 from a prerendered file, with no cookie and no `private`,\n * `no-store`, or `no-cache`\n * - is the same, except for the request ID, for a second client with another\n * host, client address, query, and value of each presence header, and with\n * a cookie, `Authorization`, `Accept-Language`, and geo headers. Why: a CDN\n * route matches only the path, a markdown `Accept`, and the presence of\n * each presence header.\n * - varies only on `Accept-Encoding`, on `Accept` for a markdown twin, and on\n * the presence headers. Each case of the presence headers gets its own\n * headers, and all cases must send the same body.\n *\n * An auth check that refuses an anonymous request keeps its pages on the\n * server. Why: the first client sends no cookie and no `Authorization`.\n *\n * @yields Each path with its CDN answer, or with the reason that the server must answer it, in the order of `paths`.\n * @example\n * for await (const page of staticPages(fetch, [\"/\", \"/about\"], { presence: [\"x-ngrok-edge\"] })) {\n * \tconsole.log(page.path, \"cdn\" in page ? \"CDN\" : page.reason);\n * }\n */\nexport async function* staticPages(\n\tfetch: PipelineFetch,\n\tpaths: readonly string[],\n\t{ presence }: { presence: readonly string[] },\n): AsyncGenerator<StaticPage> {\n\tfor (const path of paths) {\n\t\tyield await staticPage(fetch, path, presence);\n\t}\n}\n","import type { MiddlewareHandler } from \"hono\";\nimport { DEFAULT_ASSETS_PATH, readBuildManifest } from \"./build-manifest.js\";\nimport { serverInternals } from \"./create-server.js\";\nimport type { AppServer } from \"./create-server.js\";\nimport { errorAttributes } from \"./log.js\";\nimport { abortShutdownSignal } from \"./shutdown.js\";\nimport { staticPages } from \"./static-pages.js\";\nimport type { StaticPage } from \"./static-pages.js\";\nimport { keptFiles } from \"./static-files.js\";\nimport type {\n\tAppServerEnv,\n\tFetchHandler,\n\tFrameworkRuntime,\n\tHostRuntime,\n\tListenerBindings,\n\tMode,\n\tSetupInfo,\n} from \"./types.js\";\n\n/** The version of the contract between the CLI and the `appServer` export of a build. */\nexport const ENTRY_PROTOCOL = 2;\n\n/**\n * What a server build exports as `appServer`. The CLI calls it, so the copy\n * of this package in the build runs the server, and the CLI's copy runs\n * nothing.\n */\nexport type AppServerEntry = {\n\t/** The CLI refuses an entry with another version. */\n\tprotocol: typeof ENTRY_PROTOCOL;\n\t/** The app. Two entries with the same app share its plugins. */\n\tapp: AppServer;\n\t/**\n\t * Production: runs each plugin's `setup` and listens. When the host's\n\t * lifecycle stops, such as on `SIGTERM`, it shuts down.\n\t */\n\tstart: () => Promise<void>;\n\t/**\n\t * Production, for a serverless host: answers one request, and does not\n\t * listen. The first call runs each plugin's `setup`.\n\t */\n\tfetch: FetchHandler;\n\t/** Development: answers one request with the dev server inside the pipeline. */\n\tfetchDev: (\n\t\trequest: Request,\n\t\tbindings: ListenerBindings,\n\t\tdevServer: MiddlewareHandler<AppServerEnv>,\n\t) => Promise<Response>;\n\t/**\n\t * Production, for a build step: each prerendered path, with the answer\n\t * that a content delivery network (CDN) can send with no server, or the\n\t * reason that the server must answer it. The first call runs each\n\t * plugin's `setup`. See `staticPages`.\n\t */\n\tstaticPages: () => AsyncGenerator<StaticPage>;\n\t/** Runs each plugin's `onShutdown` once, up to the shutdown deadline. */\n\tstopPlugins: () => Promise<void>;\n\t/** Aborts `shutdownSignal()` of this copy of the package. */\n\tabortShutdownSignal: () => void;\n};\n\n/** Options for {@link createEntry}. */\nexport type CreateEntryOptions = {\n\t/** The app from `createServer`. */\n\tapp: AppServer;\n\t/** The run side of the host adapter, such as `host` from `@ngrok/app-server/node`. */\n\thost: HostRuntime;\n\t/** Makes the run side of the framework adapter for a mode. */\n\tframework: (mode: Mode) => FrameworkRuntime;\n\t/**\n\t * The client build, as a file path or a `file:` URL. The entry that the\n\t * Vite plugin generates sets it.\n\t * @default the framework's `clientDirectory`\n\t */\n\tclientDirectory?: string;\n};\n\n/**\n * The `appServer` export of a server build: an app from `createServer`, the\n * host, and the framework adapter for each mode. The `appServer` Vite plugin\n * generates this export. Call this for a build without the plugin.\n *\n * @example\n * export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });\n */\nexport function createEntry({\n\tapp,\n\thost,\n\tframework,\n\tclientDirectory,\n}: CreateEntryOptions): AppServerEntry {\n\tconst internals = serverInternals(app);\n\tif (internals == null) {\n\t\tthrow new Error(\n\t\t\t\"The app is not from `createServer()` of the copy of @ngrok/app-server in this build.\",\n\t\t);\n\t}\n\tinternals.setRequestStore(host.storage);\n\tconst setupInfo = async (runtime: FrameworkRuntime) => {\n\t\tconst directory = clientDirectory ?? runtime.clientDirectory;\n\t\tif (directory == null) {\n\t\t\tthrow new Error(\n\t\t\t\t`Give createEntry a clientDirectory: the ${runtime.name} adapter does not know the client build.`,\n\t\t\t);\n\t\t}\n\t\tconst files = host.files(directory);\n\t\treturn {\n\t\t\tfiles,\n\t\t\tisDataRequest: runtime.isDataRequest ?? (() => false),\n\t\t\tcontentTypes: runtime.contentTypes ?? {},\n\t\t\tgzip: host.gzip,\n\t\t\tlogger: internals.logger,\n\t\t};\n\t};\n\tlet prerenderedPaths: readonly string[] = [];\n\t/** Runs each plugin's `setup` for production, and gives the framework's run side. */\n\tconst prepareProduction = async (): Promise<FrameworkRuntime> => {\n\t\tconst runtime = framework(\"production\");\n\t\tconst shared = await setupInfo(runtime);\n\t\tconst snapshot = await shared.files.snapshot?.();\n\t\t// Why only with a snapshot: it promises that the client build does not change while the server runs.\n\t\tconst files = snapshot == null ? shared.files : keptFiles(snapshot);\n\t\tconst manifest = await readBuildManifest(files);\n\t\tconst info: SetupInfo = {\n\t\t\t...shared,\n\t\t\tfiles,\n\t\t\tmode: \"production\",\n\t\t\tprerenderedPaths: runtime.prerenderedPaths ?? manifest.prerendered,\n\t\t\tcapturedHeaders: new Map(Object.entries(manifest.headers)),\n\t\t\tscriptHashes: new Map(Object.entries(manifest.scriptHashes)),\n\t\t\tbuildId: manifest.buildId,\n\t\t\tassetsPath: manifest.assetsPath ?? DEFAULT_ASSETS_PATH,\n\t\t};\n\t\tawait internals.prepare(info);\n\t\t({ prerenderedPaths } = info);\n\t\treturn runtime;\n\t};\n\tlet preparing: Promise<FrameworkRuntime> | undefined;\n\t/**\n\t * The production run side, set up once. Why forget a failure: a serverless\n\t * instance stays up, so the next request runs each `setup` again.\n\t */\n\tconst production = async (): Promise<FrameworkRuntime> => {\n\t\tpreparing ??= prepareProduction().catch((error: unknown) => {\n\t\t\tpreparing = undefined;\n\t\t\tthrow error;\n\t\t});\n\t\treturn preparing;\n\t};\n\tlet development: FrameworkRuntime | undefined;\n\treturn {\n\t\tprotocol: ENTRY_PROTOCOL,\n\t\tapp,\n\t\tstart: async () => {\n\t\t\tconst runtime = await production();\n\t\t\tconst server = await internals.listen(runtime, host.listeners?.());\n\t\t\thost.lifecycle?.onStop(async () =>\n\t\t\t\tserver.shutdown().catch((error: unknown) => {\n\t\t\t\t\tinternals.logger.log(\"error\", \"shutdown failed\", errorAttributes(error));\n\t\t\t\t\tthrow error;\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\tfetch: async (request, bindings) => {\n\t\t\t// Why log it: the host sends a 500 with no log, and no app handler runs before setup ends.\n\t\t\tconst runtime = await production().catch((error: unknown) => {\n\t\t\t\tinternals.logger.log(\"error\", \"setup failed\", errorAttributes(error));\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\treturn app.fetch(request, { ...bindings, framework: runtime });\n\t\t},\n\t\tfetchDev: async (request, bindings, devServer) => {\n\t\t\tdevelopment ??= framework(\"development\");\n\t\t\tawait internals.prepare({\n\t\t\t\t...(await setupInfo(development)),\n\t\t\t\tmode: \"development\",\n\t\t\t\tdevServer,\n\t\t\t\tprerenderedPaths: development.prerenderedPaths,\n\t\t\t\tcapturedHeaders: new Map(),\n\t\t\t\tscriptHashes: new Map(),\n\t\t\t\t// Why none: development has no client build, and Vite's HMR updates an open tab after each edit.\n\t\t\t\tbuildId: undefined,\n\t\t\t});\n\t\t\treturn app.fetch(request, { ...bindings, framework: development });\n\t\t},\n\t\tasync *staticPages() {\n\t\t\tconst runtime = await production();\n\t\t\tyield* staticPages(\n\t\t\t\tasync (request, bindings) => app.fetch(request, { ...bindings, framework: runtime }),\n\t\t\t\tprerenderedPaths,\n\t\t\t\t{ presence: internals.presenceHeaders },\n\t\t\t);\n\t\t},\n\t\tstopPlugins: internals.stopPlugins,\n\t\tabortShutdownSignal,\n\t};\n}\n\n/**\n * Whether a value is an entry of this protocol version.\n *\n * @example\n * isAppServerEntry((await import(\"./build/server/app-server.js\")).appServer); // => true\n */\nexport function isAppServerEntry(value: unknown): value is AppServerEntry {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"protocol\" in value &&\n\t\tvalue.protocol === ENTRY_PROTOCOL\n\t);\n}\n"],"mappings":";;;;;;;AAiCA,MAAM,8BAAc,IAAI,IAAI,CAAC,gBAAgB,MAAM,CAAC;;AAGpD,MAAM,0BAAU,IAAI,IAAI;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;AACD,CAAC;;AAGD,MAAM,iBAAiB;;;;;;;AAQvB,MAAM,aAAa;;AAGnB,MAAM,uBAAuB;;;;;;;;;;AAmB7B,MAAM,UAAU,CACf;CACC,QAAQ;CACR,OAAO;CACP,SAAS;CACT,cAAc;CACd,SAAS;EAAE,QAAQ;EAAgB,cAAc;CAAmB;AACrE,GACA;CACC,QAAQ;CACR,OAAO;CACP,SAAS;CACT,cAAc;CACd,SAAS;EACR,QAAQ;EACR,mBAAmB;EACnB,eAAe;EACf,QAAQ;EACR,SAAS;EACT,cAAc;EACd,oBAAoB;EACpB,uBAAuB;EACvB,8BAA8B;C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AI,IAAI;IACzB,8BAAc,IAAI,IAAI;IAEtB,SAAS;GACV,CAAC;GACD,OAAO,IAAI,MAAM,SAAS;IAAE,GAAG;IAAU,WAAW;GAAY,CAAC;EAClE;EACA,OAAO,cAAc;GACpB,MAAM,UAAU,MAAM,WAAW;GACjC,OAAO,YACN,OAAO,SAAS,aAAa,IAAI,MAAM,SAAS;IAAE,GAAG;IAAU,WAAW;GAAQ,CAAC,GACnF,kBACA,EAAE,UAAU,UAAU,gBAAgB,CACvC;EACD;EACA,aAAa,UAAU;EACvB;CACD;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,MAAM;AAER"}
|
|
@@ -54,6 +54,11 @@ type HostOutput = {
|
|
|
54
54
|
clientDirectory: string;
|
|
55
55
|
/** The server entry, such as `build/server/app-server.js`. */
|
|
56
56
|
entryFile: string;
|
|
57
|
+
/**
|
|
58
|
+
* The URL path of Vite's `build.assetsDir` in the client build, such as
|
|
59
|
+
* `/assets/`. Its files have content hashes in their names.
|
|
60
|
+
*/
|
|
61
|
+
assetsPath: string;
|
|
57
62
|
};
|
|
58
63
|
/** Options for {@link appServer}. */
|
|
59
64
|
type AppServerOptions = {
|
|
@@ -124,4 +129,4 @@ declare function serverEntrySource({ framework, host, appModule, clientDirectory
|
|
|
124
129
|
*/
|
|
125
130
|
declare function appServer(options?: AppServerOptions): Plugin[];
|
|
126
131
|
export { SERVER_ENTRY_ID as a, HostOutput as i, FrameworkBuild as n, appServer as o, HostBuild as r, serverEntrySource as s, AppServerOptions as t };
|
|
127
|
-
//# sourceMappingURL=index-
|
|
132
|
+
//# sourceMappingURL=index-Db7dspq6.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { C as SetupInfo, E as ResponseEdge, S as ServerBindings, T as StaticFiles, _ as RequestContext, a as FrameworkRuntime, b as ResponseHeaders, c as HostRuntime, d as ListenerBindings, f as ListenerStartOptions, g as Plugin, h as Mode, i as FileInfo, l as Lifecycle, m as LogSink, n as ByteRange, o as FrameworkRuntimeFactory, p as LogLevel, r as FetchHandler, s as HeaderHook, t as AppServerEnv, u as Listener, v as RequestLogger, w as StartedListener, x as SentResponse, y as RequestStore } from "./types-
|
|
2
|
-
import { A as
|
|
3
|
-
import { n as TrailingSlashOptions, r as trailingSlash, t as TrailingSlash } from "./trailing-slash-
|
|
4
|
-
import { n as CreateEntryOptions, r as createEntry, t as AppServerEntry } from "./entry-
|
|
1
|
+
import { C as SetupInfo, E as ResponseEdge, S as ServerBindings, T as StaticFiles, _ as RequestContext, a as FrameworkRuntime, b as ResponseHeaders, c as HostRuntime, d as ListenerBindings, f as ListenerStartOptions, g as Plugin, h as Mode, i as FileInfo, l as Lifecycle, m as LogSink, n as ByteRange, o as FrameworkRuntimeFactory, p as LogLevel, r as FetchHandler, s as HeaderHook, t as AppServerEnv, u as Listener, v as RequestLogger, w as StartedListener, x as SentResponse, y as RequestStore } from "./types-j29vspx_.js";
|
|
2
|
+
import { A as buildId, C as RedirectRule, D as HealthOptions, E as noindex, M as accessLog, O as health, S as securityHeaders, T as NoindexOptions, _ as requestId, a as createServer, b as SecurityHeadersOptions, c as assets, d as PUBLIC_ENV_SCRIPT_ID, f as RuntimeEnv, g as RequestIdOptions, h as runtimeEnv, i as RunningServer, j as AccessLogOptions, k as BuildIdOptions, l as prerendered, m as StandardSchemaV1, n as CreateServerOptions, o as defaultPlugins, p as RuntimeEnvOptions, r as DefaultPluginsOptions, s as PrerenderedOptions, t as AppServer, u as InferOutput, v as ContentSecurityPolicyOptions, w as redirects, x as contentSecurityPolicy, y as SecurityHeaderValues } from "./create-server-D4-nVOVJ.js";
|
|
3
|
+
import { n as TrailingSlashOptions, r as trailingSlash, t as TrailingSlash } from "./trailing-slash-CFSv_Gzx.js";
|
|
4
|
+
import { n as CreateEntryOptions, r as createEntry, t as AppServerEntry } from "./entry-BPrgE_6K.js";
|
|
5
5
|
import { Context, Next } from "hono";
|
|
6
6
|
/** One server-sent event. */
|
|
7
7
|
type ServerSentEvent = {
|
|
@@ -95,16 +95,6 @@ type BodyLimitOptions = {
|
|
|
95
95
|
* createServer({ plugins: [requestId(), accessLog(), bodyLimit({ maxBytes: 1_048_576 })] });
|
|
96
96
|
*/
|
|
97
97
|
export declare function bodyLimit({ maxBytes }: BodyLimitOptions): Plugin;
|
|
98
|
-
/**
|
|
99
|
-
* Sets `X-Robots-Tag: noindex, nofollow` on each response, so a search
|
|
100
|
-
* engine does not index a preview deploy. Turn it on from the environment
|
|
101
|
-
* with the `noindex` option of `defaultPlugins()`, which puts it before the
|
|
102
|
-
* static stages, so it also sees prerendered pages.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* defaultPlugins({ noindex: process.env.PREVIEW === "1" });
|
|
106
|
-
*/
|
|
107
|
-
export declare function noindex(): Plugin;
|
|
108
98
|
/**
|
|
109
99
|
* Sets `Cache-Control: private, no-cache` on each HTML document and each
|
|
110
100
|
* framework data response, such as a React Router `.data` request, that has
|
|
@@ -188,5 +178,5 @@ export declare function requestContext(): RequestContext | undefined;
|
|
|
188
178
|
* shutdownSignal().addEventListener("abort", () => clearInterval(timer), { once: true });
|
|
189
179
|
*/
|
|
190
180
|
export declare function shutdownSignal(): AbortSignal;
|
|
191
|
-
export { type AccessLogOptions, type AppServer, type AppServerEntry, type AppServerEnv, type BodyLimitOptions, type BuildIdOptions, type ByteRange, type ContentSecurityPolicyOptions, type CreateEntryOptions, type CreateServerOptions, type DefaultPluginsOptions, type EventStreamOptions, type EventStreamSink, type FetchHandler, type FileInfo, type FrameworkRuntime, type FrameworkRuntimeFactory, type HeaderHook, type HealthOptions, type HostRuntime, type InferOutput, type Lifecycle, type Listener, type ListenerBindings, type ListenerStartOptions, type LogLevel, type LogSink, type Mode, PUBLIC_ENV_SCRIPT_ID, type Plugin, type PrerenderedOptions, type RedirectRule, type RequestContext, type RequestIdOptions, type RequestLogger, type RequestStore, ResponseEdge, type ResponseHeaders, type RunningServer, type RuntimeEnv, type RuntimeEnvOptions, type SecurityHeaderValues, type SecurityHeadersOptions, type SentResponse, type ServerBindings, type ServerSentEvent, type SetupInfo, type StandardSchemaV1, type StartedListener, type StaticFiles, type TrailingSlash, type TrailingSlashOptions, accessLog, assets, buildId, contentSecurityPolicy, createEntry, createServer, defaultPlugins, health, prerendered, redirects, requestId, runtimeEnv, securityHeaders, trailingSlash };
|
|
181
|
+
export { type AccessLogOptions, type AppServer, type AppServerEntry, type AppServerEnv, type BodyLimitOptions, type BuildIdOptions, type ByteRange, type ContentSecurityPolicyOptions, type CreateEntryOptions, type CreateServerOptions, type DefaultPluginsOptions, type EventStreamOptions, type EventStreamSink, type FetchHandler, type FileInfo, type FrameworkRuntime, type FrameworkRuntimeFactory, type HeaderHook, type HealthOptions, type HostRuntime, type InferOutput, type Lifecycle, type Listener, type ListenerBindings, type ListenerStartOptions, type LogLevel, type LogSink, type Mode, type NoindexOptions, PUBLIC_ENV_SCRIPT_ID, type Plugin, type PrerenderedOptions, type RedirectRule, type RequestContext, type RequestIdOptions, type RequestLogger, type RequestStore, ResponseEdge, type ResponseHeaders, type RunningServer, type RuntimeEnv, type RuntimeEnvOptions, type SecurityHeaderValues, type SecurityHeadersOptions, type SentResponse, type ServerBindings, type ServerSentEvent, type SetupInfo, type StandardSchemaV1, type StartedListener, type StaticFiles, type TrailingSlash, type TrailingSlashOptions, accessLog, assets, buildId, contentSecurityPolicy, createEntry, createServer, defaultPlugins, health, noindex, prerendered, redirects, requestId, runtimeEnv, securityHeaders, trailingSlash };
|
|
192
182
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as requestContext } from "./request-context-BtQ87VYb.js";
|
|
2
2
|
import { a as replaceResponse, o as withHeaderHook, s as writableHeaders } from "./header-hook-Vzw9J9BY.js";
|
|
3
|
-
import { r as buildId, s as optionPlugin } from "./build-id-
|
|
3
|
+
import { r as buildId, s as optionPlugin } from "./build-id-B0448vZH.js";
|
|
4
4
|
import { r as jsonSink } from "./log-BP6xXXZl.js";
|
|
5
5
|
import { t as ResponseEdge } from "./response-edge-Bc1-C_Cx.js";
|
|
6
|
-
import { a as streamingCompress, b as
|
|
7
|
-
import { t as createEntry } from "./entry-
|
|
6
|
+
import { _ as assets, a as streamingCompress, b as prefersMarkdown, c as securityHeaders, d as noindex, f as health, g as accessLog, h as bodyLimit, l as redirects, m as shutdownSignal, n as defaultPlugins, o as requestId, s as contentSecurityPolicy, t as createServer, u as privateDocuments, v as prerendered, y as trailingSlash } from "./create-server-jMl2ltHD.js";
|
|
7
|
+
import { t as createEntry } from "./entry-D9H4LA9c.js";
|
|
8
8
|
|
|
9
9
|
// src/core/event-stream.ts
|
|
10
10
|
function formatEvent({ data, event, id }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createServer } from "./create-server-
|
|
2
|
-
import { n as isAppServerEntry, t as createEntry } from "./entry-
|
|
1
|
+
import { t as createServer } from "./create-server-jMl2ltHD.js";
|
|
2
|
+
import { n as isAppServerEntry, t as createEntry } from "./entry-D9H4LA9c.js";
|
|
3
3
|
import { t as host } from "./node-C1qudLs_.js";
|
|
4
4
|
|
|
5
5
|
// src/cli/load-entry.ts
|
|
@@ -34,4 +34,4 @@ async function loadEntry(build) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export { loadEntry as t };
|
|
37
|
-
//# sourceMappingURL=load-entry-
|
|
37
|
+
//# sourceMappingURL=load-entry-D7r0mjEp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-entry-
|
|
1
|
+
{"version":3,"file":"load-entry-D7r0mjEp.js","names":[],"sources":["../src/cli/load-entry.ts"],"sourcesContent":["import { createServer } from \"../core/create-server.js\";\nimport { createEntry, ENTRY_PROTOCOL, isAppServerEntry } from \"../core/entry.js\";\nimport type { AppServerEntry } from \"../core/entry.js\";\nimport { host } from \"../node/index.js\";\n\n/** Entries that this copy made for plain React Router builds, by build module. */\nconst plainEntries = new WeakMap<object, AppServerEntry>();\n\n/**\n * The entry that runs a server build: its `appServer` export when the\n * `appServer` Vite plugin made it, else this copy of the package over a\n * plain React Router build, on the node host, with the default plugins.\n */\nexport async function loadEntry(build: unknown): Promise<AppServerEntry> {\n\tif (typeof build !== \"object\" || build == null) {\n\t\tthrow new Error(\"The server build entry is not a module.\");\n\t}\n\tconst exported: unknown = Reflect.get(build, \"appServer\");\n\tif (exported != null) {\n\t\tif (!isAppServerEntry(exported)) {\n\t\t\tthrow new Error(\n\t\t\t\t`The build's @ngrok/app-server does not use entry protocol ${ENTRY_PROTOCOL}. Install the same version of @ngrok/app-server that the build uses.`,\n\t\t\t);\n\t\t}\n\t\treturn exported;\n\t}\n\tconst known = plainEntries.get(build);\n\tif (known != null) {\n\t\treturn known;\n\t}\n\tconst { isServerBuild, runtime } = await import(\"../react-router/index.js\");\n\tif (!isServerBuild(build)) {\n\t\tthrow new Error(\"The server build entry is not a React Router server build.\");\n\t}\n\tconst entry = createEntry({\n\t\tapp: createServer({\n\t\t\ttrustForwardedProto: process.env.TRUST_FORWARDED_PROTO === \"1\",\n\t\t\ttrustedProxyHops: Number(process.env.TRUSTED_PROXY_HOPS ?? 0),\n\t\t}),\n\t\thost,\n\t\tframework: (mode) => runtime(build, { mode }),\n\t});\n\tplainEntries.set(build, entry);\n\treturn entry;\n}\n"],"mappings":";;;;;;AAMA,MAAM,+BAAe,IAAI,QAAgC;;;;;;AAOzD,eAAsB,UAAU,OAAyC;CACxE,IAAI,OAAO,UAAU,YAAY,SAAS,MACzC,MAAM,IAAI,MAAM,yCAAyC;CAE1D,MAAM,WAAoB,QAAQ,IAAI,OAAO,WAAW;CACxD,IAAI,YAAY,MAAM;EACrB,IAAI,CAAC,iBAAiB,QAAQ,GAC7B,MAAM,IAAI,MACT,+DAA4E,qEAC7E;EAED,OAAO;CACR;CACA,MAAM,QAAQ,aAAa,IAAI,KAAK;CACpC,IAAI,SAAS,MACZ,OAAO;CAER,MAAM,EAAE,eAAe,YAAY,MAAM,OAAO;CAChD,IAAI,CAAC,cAAc,KAAK,GACvB,MAAM,IAAI,MAAM,4DAA4D;CAE7E,MAAM,QAAQ,YAAY;EACzB,KAAK,aAAa;GACjB,qBAAqB,QAAQ,IAAI,0BAA0B;GAC3D,kBAAkB,OAAO,QAAQ,IAAI,sBAAsB,CAAC;EAC7D,CAAC;EACD;EACA,YAAY,SAAS,QAAQ,OAAO,EAAE,KAAK,CAAC;CAC7C,CAAC;CACD,aAAa,IAAI,OAAO,KAAK;CAC7B,OAAO;AACR"}
|
package/dist/node-vite.d.ts
CHANGED
package/dist/node.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as StaticFiles, c as HostRuntime, d as ListenerBindings, t as AppServerEnv, u as Listener } from "./types-
|
|
1
|
+
import { T as StaticFiles, c as HostRuntime, d as ListenerBindings, t as AppServerEnv, u as Listener } from "./types-j29vspx_.js";
|
|
2
2
|
import { MiddlewareHandler } from "hono";
|
|
3
3
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
4
|
/** A Connect middleware, such as `vite.middlewares`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as FrameworkBuild } from "./index-
|
|
1
|
+
import { n as FrameworkBuild } from "./index-Db7dspq6.js";
|
|
2
2
|
/**
|
|
3
3
|
* The build side of the React Router adapter. `appServer` uses it when the
|
|
4
4
|
* Vite config has the React Router plugin, so pass it only to override that.
|
package/dist/react-router.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as RequestContext, a as FrameworkRuntime, h as Mode } from "./types-
|
|
1
|
+
import { _ as RequestContext, a as FrameworkRuntime, h as Mode } from "./types-j29vspx_.js";
|
|
2
2
|
import { ServerBuild } from "react-router";
|
|
3
3
|
/** What the server puts in React Router's context for each request. */
|
|
4
4
|
export type AppServerContext = RequestContext;
|
|
@@ -23,7 +23,8 @@ export declare const appServerContext: import("react-router").RouterContext<Requ
|
|
|
23
23
|
export declare function isServerBuild(value: unknown): value is ServerBuild;
|
|
24
24
|
/**
|
|
25
25
|
* The run side of the React Router adapter, for a server build. Each request
|
|
26
|
-
* gets a `RouterContextProvider` that holds {@link appServerContext}.
|
|
26
|
+
* gets a `RouterContextProvider` that holds {@link appServerContext}. The
|
|
27
|
+
* access log gets the route pattern that React Router matched.
|
|
27
28
|
*
|
|
28
29
|
* @example
|
|
29
30
|
* const framework = runtime(build, { mode: "production" });
|
package/dist/react-router.js
CHANGED
|
@@ -20,6 +20,33 @@ const appServerContext = createContext({
|
|
|
20
20
|
cspNonce: void 0,
|
|
21
21
|
clientAddress: void 0
|
|
22
22
|
});
|
|
23
|
+
/** The Hono context of the request, for {@link recordRoutePattern}. */
|
|
24
|
+
const honoContext = createContext();
|
|
25
|
+
/**
|
|
26
|
+
* Sets `routePattern` on the Hono context to the route pattern that React
|
|
27
|
+
* Router matched, such as `/domains/:domainId`, so the access log writes
|
|
28
|
+
* `http.route`. Why a root middleware: it runs for each document, data, and
|
|
29
|
+
* resource request, and it costs less for each request than a request
|
|
30
|
+
* handler instrumentation.
|
|
31
|
+
*/
|
|
32
|
+
const recordRoutePattern = async ({ pattern, context }, next) => {
|
|
33
|
+
if (pattern !== "") context.get(honoContext).set("routePattern", pattern.startsWith("/") ? pattern : `/${pattern}`);
|
|
34
|
+
return next();
|
|
35
|
+
};
|
|
36
|
+
/** `build` with {@link recordRoutePattern} before the middleware of each root route. */
|
|
37
|
+
function withRoutePattern(build) {
|
|
38
|
+
const routes = Object.fromEntries(Object.entries(build.routes).map(([id, route]) => [id, route == null || route.parentId != null ? route : {
|
|
39
|
+
...route,
|
|
40
|
+
module: {
|
|
41
|
+
...route.module,
|
|
42
|
+
middleware: [recordRoutePattern, ...route.module.middleware ?? []]
|
|
43
|
+
}
|
|
44
|
+
}]));
|
|
45
|
+
return {
|
|
46
|
+
...build,
|
|
47
|
+
routes
|
|
48
|
+
};
|
|
49
|
+
}
|
|
23
50
|
/**
|
|
24
51
|
* Whether a module is a React Router server build.
|
|
25
52
|
*
|
|
@@ -31,7 +58,8 @@ function isServerBuild(value) {
|
|
|
31
58
|
}
|
|
32
59
|
/**
|
|
33
60
|
* The run side of the React Router adapter, for a server build. Each request
|
|
34
|
-
* gets a `RouterContextProvider` that holds {@link appServerContext}.
|
|
61
|
+
* gets a `RouterContextProvider` that holds {@link appServerContext}. The
|
|
62
|
+
* access log gets the route pattern that React Router matched.
|
|
35
63
|
*
|
|
36
64
|
* @example
|
|
37
65
|
* const framework = runtime(build, { mode: "production" });
|
|
@@ -39,7 +67,7 @@ function isServerBuild(value) {
|
|
|
39
67
|
function runtime(build, { mode }) {
|
|
40
68
|
if (!isServerBuild(build)) throw new Error("The server module is not a React Router server build.");
|
|
41
69
|
if (build.publicPath !== "/") throw new Error(`@ngrok/app-server serves a build at "/" only, and this build has the publicPath "${build.publicPath}".`);
|
|
42
|
-
const handler = createRequestHandler(build, mode);
|
|
70
|
+
const handler = createRequestHandler(withRoutePattern(build), mode);
|
|
43
71
|
const manifestPath = build.routeDiscovery.mode === "lazy" ? [build.basename ?? "", build.routeDiscovery.manifestPath || "/__manifest"].join("/").replaceAll(/\/+/gu, "/") : void 0;
|
|
44
72
|
return {
|
|
45
73
|
name: "react-router",
|
|
@@ -50,6 +78,7 @@ function runtime(build, { mode }) {
|
|
|
50
78
|
fetch: async (request, context) => {
|
|
51
79
|
const routerContext = new RouterContextProvider();
|
|
52
80
|
routerContext.set(appServerContext, requestContextValues(context));
|
|
81
|
+
routerContext.set(honoContext, context);
|
|
53
82
|
return handler(request, routerContext);
|
|
54
83
|
}
|
|
55
84
|
};
|