@ngrok/app-server 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -10
- package/dist/cli.js +3 -3
- package/dist/client.js +1 -1
- package/dist/{compress-CO0Nwc8x.js → compress-Cp5NfXCC.js} +138 -29
- package/dist/compress-Cp5NfXCC.js.map +1 -0
- package/dist/{create-server-C_90R50y.js → create-server-C63luLkn.js} +71 -30
- package/dist/create-server-C63luLkn.js.map +1 -0
- package/dist/{create-server-kxyhCdhv.d.ts → create-server-DKJ0wASH.d.ts} +33 -13
- package/dist/{entry-65IESBSA.js → entry-BSbsQ_kq.js} +13 -5
- package/dist/entry-BSbsQ_kq.js.map +1 -0
- package/dist/{entry-CNL4OsEn.d.ts → entry-C9bBcYeP.d.ts} +3 -3
- package/dist/index.d.ts +18 -5
- package/dist/index.js +6 -6
- package/dist/{load-entry-svVuPIFq.js → load-entry-DgZyPtoD.js} +4 -4
- package/dist/{load-entry-svVuPIFq.js.map → load-entry-DgZyPtoD.js.map} +1 -1
- package/dist/log-CW_g1pWk.js +304 -0
- package/dist/log-CW_g1pWk.js.map +1 -0
- package/dist/{node-Bgzhwix0.js → node-DBwgrye_.js} +2 -2
- package/dist/{node-Bgzhwix0.js.map → node-DBwgrye_.js.map} +1 -1
- package/dist/{node-DFI5TjTk.js → node-DiMwdTOC.js} +4 -4
- package/dist/{node-DFI5TjTk.js.map → node-DiMwdTOC.js.map} +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/react-router.d.ts +2 -2
- package/dist/react-router.js +3 -4
- package/dist/react-router.js.map +1 -1
- package/dist/request-context-BdAH1D-2.js +80 -0
- package/dist/request-context-BdAH1D-2.js.map +1 -0
- package/dist/{response-edge-D3CAjukJ.js → response-edge-7eUl2ewl.js} +3 -3
- package/dist/response-edge-7eUl2ewl.js.map +1 -0
- package/dist/{response-writer-5SOKsW3C.js → response-writer-CLtCseu5.js} +3 -3
- package/dist/{response-writer-5SOKsW3C.js.map → response-writer-CLtCseu5.js.map} +1 -1
- package/dist/{serve-DKoZxZj4.js → serve-DCaIBTM-.js} +2 -2
- package/dist/{serve-DKoZxZj4.js.map → serve-DCaIBTM-.js.map} +1 -1
- package/dist/{start-3_WlRLdK.js → start-D2IVWkow.js} +29 -13
- package/dist/start-D2IVWkow.js.map +1 -0
- package/dist/tanstack-start.d.ts +2 -2
- package/dist/tanstack-start.js +1 -1
- package/dist/{tcp-CKMCT9RP.js → tcp-B8aFGQRB.js} +2 -2
- package/dist/{tcp-CKMCT9RP.js.map → tcp-B8aFGQRB.js.map} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +4 -4
- package/dist/{trailing-slash-DeOUxMYo.d.ts → trailing-slash-D_52DJaQ.d.ts} +2 -2
- package/dist/{types-BKJxtIuj.d.ts → types-C_I3i62n.d.ts} +32 -4
- package/dist/vercel.d.ts +2 -2
- package/dist/vercel.js +4 -4
- package/package.json +1 -1
- package/dist/compress-CO0Nwc8x.js.map +0 -1
- package/dist/create-server-C_90R50y.js.map +0 -1
- package/dist/entry-65IESBSA.js.map +0 -1
- package/dist/log-C8LGQ23s.js +0 -149
- package/dist/log-C8LGQ23s.js.map +0 -1
- package/dist/request-context-BtQ87VYb.js +0 -40
- package/dist/request-context-BtQ87VYb.js.map +0 -1
- package/dist/response-edge-D3CAjukJ.js.map +0 -1
- package/dist/start-3_WlRLdK.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as loadEntry } from "./load-entry-
|
|
1
|
+
import { t as loadEntry } from "./load-entry-DgZyPtoD.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
@@ -26,4 +26,4 @@ async function serve({ buildPath }) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export { serve };
|
|
29
|
-
//# sourceMappingURL=serve-
|
|
29
|
+
//# sourceMappingURL=serve-DCaIBTM-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve-
|
|
1
|
+
{"version":3,"file":"serve-DCaIBTM-.js","names":[],"sources":["../src/cli/serve.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { loadEntry } from \"./load-entry.js\";\n\n/**\n * Where `app-server serve` looks for the server build when no path is given:\n * the node host's entry in the React Router and Vite output layouts, then a\n * plain React Router build.\n */\nexport const DEFAULT_BUILD_PATHS = [\n\t\"build/server/app-server.js\",\n\t\"dist/server/app-server.js\",\n\t\"build/server/index.js\",\n];\n\n/**\n * Loads a production server build and starts it. The copy of this package in\n * the build runs the server when the build has one: see `loadEntry`.\n */\nexport async function serve({ buildPath }: { buildPath: string | undefined }): Promise<void> {\n\tconst path = buildPath ?? DEFAULT_BUILD_PATHS.find((candidate) => existsSync(candidate));\n\tif (path == null) {\n\t\tthrow new Error(\n\t\t\t`No server build found. Build the app, or pass its path. Looked for: ${DEFAULT_BUILD_PATHS.join(\", \")}.`,\n\t\t);\n\t}\n\tconst build: unknown = await import(pathToFileURL(resolve(path)).href);\n\tawait (await loadEntry(build)).start();\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,sBAAsB;CAClC;CACA;CACA;AACD;;;;;AAMA,eAAsB,MAAM,EAAE,aAA+D;CAC5F,MAAM,OAAO,aAAa,oBAAoB,MAAM,cAAc,WAAW,SAAS,CAAC;CACvF,IAAI,QAAQ,MACX,MAAM,IAAI,MACT,uEAAuE,oBAAoB,KAAK,IAAI,EAAE,EACvG;CAED,MAAM,QAAiB,MAAM,OAAO,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC;CACjE,OAAO,MAAM,UAAU,KAAK,EAAC,CAAE,MAAM;AACtC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as parsePort } from "./tcp-
|
|
2
|
-
import {
|
|
3
|
-
import { i as exitAfterFlush, n as devServerStage } from "./node-
|
|
4
|
-
import { t as requestListener } from "./response-writer-
|
|
1
|
+
import { t as parsePort } from "./tcp-B8aFGQRB.js";
|
|
2
|
+
import { r as hookSink, s as textSink, t as asError } from "./log-CW_g1pWk.js";
|
|
3
|
+
import { i as exitAfterFlush, n as devServerStage } from "./node-DiMwdTOC.js";
|
|
4
|
+
import { t as requestListener } from "./response-writer-CLtCseu5.js";
|
|
5
5
|
import { t as SERVER_ENTRY_ID } from "./vite-DPiSKHDn.js";
|
|
6
|
-
import { t as loadEntry } from "./load-entry-
|
|
6
|
+
import { t as loadEntry } from "./load-entry-DgZyPtoD.js";
|
|
7
7
|
import { t as listenerUrl } from "./listen-options-7TaXjyrk.js";
|
|
8
8
|
import { styleText } from "node:util";
|
|
9
9
|
import { createServer } from "node:http";
|
|
@@ -214,14 +214,18 @@ async function start() {
|
|
|
214
214
|
directory: viteServer.config.publicDir,
|
|
215
215
|
base: viteServer.config.base
|
|
216
216
|
}) });
|
|
217
|
-
const sink = textSink();
|
|
217
|
+
const sink = hookSink(textSink());
|
|
218
218
|
const apps = servedApps();
|
|
219
219
|
const listener = requestListener(async (request, bindings) => {
|
|
220
220
|
try {
|
|
221
221
|
return await apps.serve(await loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)), async (entry) => entry.fetchDev(request, bindings, devServer));
|
|
222
222
|
} catch (error) {
|
|
223
223
|
if (error instanceof Error) viteServer.ssrFixStacktrace(error);
|
|
224
|
-
sink.log(
|
|
224
|
+
sink.log({
|
|
225
|
+
level: "error",
|
|
226
|
+
message: "dev request failed",
|
|
227
|
+
attributes: { error: asError(error) }
|
|
228
|
+
});
|
|
225
229
|
return new Response(error instanceof Error ? error.stack ?? error.message : String(error), {
|
|
226
230
|
status: 500,
|
|
227
231
|
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
@@ -238,12 +242,20 @@ async function start() {
|
|
|
238
242
|
hostname,
|
|
239
243
|
strictPort: viteServer.config.server.strictPort,
|
|
240
244
|
onPortInUse: (inUse) => {
|
|
241
|
-
sink.log(
|
|
245
|
+
sink.log({
|
|
246
|
+
level: "info",
|
|
247
|
+
message: "port in use, trying the next port",
|
|
248
|
+
attributes: { "server.port": inUse }
|
|
249
|
+
});
|
|
242
250
|
},
|
|
243
251
|
onWildcardInUse: (inUse) => {
|
|
244
|
-
sink.log(
|
|
245
|
-
"
|
|
246
|
-
"
|
|
252
|
+
sink.log({
|
|
253
|
+
level: "warn",
|
|
254
|
+
message: "port in use on a wildcard address",
|
|
255
|
+
attributes: {
|
|
256
|
+
"server.port": inUse,
|
|
257
|
+
"server.address": hostname
|
|
258
|
+
}
|
|
247
259
|
});
|
|
248
260
|
}
|
|
249
261
|
});
|
|
@@ -262,7 +274,11 @@ async function start() {
|
|
|
262
274
|
});
|
|
263
275
|
});
|
|
264
276
|
const viteClosed = viteServer.close().catch((error) => {
|
|
265
|
-
sink.log(
|
|
277
|
+
sink.log({
|
|
278
|
+
level: "error",
|
|
279
|
+
message: "Vite close failed",
|
|
280
|
+
attributes: { error: asError(error) }
|
|
281
|
+
});
|
|
266
282
|
process.exitCode = 1;
|
|
267
283
|
});
|
|
268
284
|
Promise.all([
|
|
@@ -305,4 +321,4 @@ function viteHostname(host) {
|
|
|
305
321
|
}
|
|
306
322
|
|
|
307
323
|
export { start };
|
|
308
|
-
//# sourceMappingURL=start-
|
|
324
|
+
//# sourceMappingURL=start-D2IVWkow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-D2IVWkow.js","names":["createServer","createHttpServer"],"sources":["../src/cli/dev-urls.ts","../src/cli/served-apps.ts","../src/cli/start-port.ts","../src/cli/start.ts"],"sourcesContent":["import { networkInterfaces } from \"node:os\";\nimport { styleText } from \"node:util\";\nimport { listenerUrl } from \"../node/runtimes/listen-options.js\";\n\nconst wildcardHosts = new Set([\"\", \"0.0.0.0\", \"::\"]);\nconst loopbackHosts = new Set([\"localhost\", \"127.0.0.1\", \"::1\"]);\n\ntype DevUrl = { local: boolean; url: string; interfaceName: string | undefined };\n\n/**\n * The lines that `app-server start` prints when it listens, in the format of `vite dev`. Each URL\n * ends with `base`, Vite's base path. A wildcard host gets a `localhost` line, then one line for\n * each IPv4 (Internet Protocol version 4) interface.\n *\n * @example\n * devUrlLines({ hostname: \"localhost\", port: 3000, base: \"/\" }); // => [\" ➜ Local: http://localhost:3000/\"]\n */\nexport function devUrlLines(\n\t{ hostname, port, base }: { hostname: string | undefined; port: number; base: string },\n\tinterfaces = networkInterfaces(),\n): string[] {\n\tconst urlOf = (host: string) => `${listenerUrl(host, port).slice(0, -1)}${base}`;\n\tconst addresses = Object.entries(interfaces).flatMap(([name, details = []]) =>\n\t\tdetails.map(({ address, family }) => ({ name, address, family })),\n\t);\n\t// Why a `localhost` line with no lookup: a host with no IPv4 loopback still gets a URL to open.\n\tconst urls: DevUrl[] =\n\t\thostname == null || wildcardHosts.has(hostname)\n\t\t\t? [\n\t\t\t\t\t{ local: true, url: urlOf(\"localhost\"), interfaceName: undefined },\n\t\t\t\t\t...addresses\n\t\t\t\t\t\t.filter(({ address, family }) => family === \"IPv4\" && address !== \"127.0.0.1\")\n\t\t\t\t\t\t.map(({ name, address }) => ({\n\t\t\t\t\t\t\tlocal: false,\n\t\t\t\t\t\t\turl: urlOf(address),\n\t\t\t\t\t\t\tinterfaceName: name,\n\t\t\t\t\t\t})),\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t{\n\t\t\t\t\t\tlocal: loopbackHosts.has(hostname),\n\t\t\t\t\t\turl: urlOf(hostname),\n\t\t\t\t\t\tinterfaceName: addresses.find(({ address }) => address === hostname)?.name,\n\t\t\t\t\t},\n\t\t\t\t];\n\tconst width = Math.max(0, ...urls.filter(({ local }) => !local).map(({ url }) => url.length));\n\treturn urls.map(({ local, url, interfaceName }) => {\n\t\tconst label = styleText(\"bold\", local ? \"Local\" : \"Network\") + (local ? \": \" : \": \");\n\t\tconst link = styleText(\n\t\t\t\"cyan\",\n\t\t\turl.replace(`:${port}/`, `:${styleText(\"bold\", String(port))}/`),\n\t\t);\n\t\tconst suffix =\n\t\t\tlocal || interfaceName == null\n\t\t\t\t? \"\"\n\t\t\t\t: \" \".repeat(width - url.length + 2) + styleText(\"dim\", interfaceName);\n\t\treturn ` ${styleText(\"green\", \"➜\")} ${label}${link}${suffix}`;\n\t});\n}\n","import type { AppServerEntry } from \"../core/entry.js\";\n\ntype ServedApp = { entry: AppServerEntry; pending: number; replaced: boolean };\n\n/** What {@link servedApps} returns. */\ntype ServedApps = {\n\t/** Runs `handle` for a request that `entry` serves. */\n\tserve: <Result>(\n\t\tentry: AppServerEntry,\n\t\thandle: (entry: AppServerEntry) => Promise<Result>,\n\t) => Promise<Result>;\n\t/**\n\t * At exit: aborts `shutdownSignal()` and runs the `onShutdown` hooks of each\n\t * app still held. Resolves when the hooks finish or pass the deadline.\n\t */\n\tstopAll: () => Promise<void>;\n};\n\n/**\n * Tracks the apps that `app-server start` serves. An edit to `server.ts` makes a\n * new app, and the old app's plugins still hold what their `setup` opened.\n * When the last request that the old app took returns, its `onShutdown` hooks\n * run, and the tracker lets go of it. A route edit makes a new entry with the\n * same app, which keeps its plugins.\n */\nexport function servedApps(): ServedApps {\n\tlet current: ServedApp | undefined;\n\tconst served = new Set<ServedApp>();\n\t// Why keep the app until its hooks settle: `stopAll` must wait for hooks that already run.\n\t// `stopPlugins` runs the hooks once, so a second call only waits.\n\tconst retire = async (app: ServedApp) => {\n\t\ttry {\n\t\t\tawait app.entry.stopPlugins();\n\t\t} finally {\n\t\t\tserved.delete(app);\n\t\t}\n\t};\n\treturn {\n\t\tserve: async (entry, handle) => {\n\t\t\tif (current?.entry.app === entry.app) {\n\t\t\t\tcurrent.entry = entry;\n\t\t\t} else {\n\t\t\t\tif (current != null) {\n\t\t\t\t\tcurrent.replaced = true;\n\t\t\t\t\tif (current.pending === 0) {\n\t\t\t\t\t\tvoid retire(current);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrent = { entry, pending: 0, replaced: false };\n\t\t\t\tserved.add(current);\n\t\t\t}\n\t\t\tconst app = current;\n\t\t\tapp.pending += 1;\n\t\t\ttry {\n\t\t\t\treturn await handle(entry);\n\t\t\t} finally {\n\t\t\t\tapp.pending -= 1;\n\t\t\t\tif (app.replaced && app.pending === 0) {\n\t\t\t\t\tvoid retire(app);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tstopAll: async () => {\n\t\t\tawait Promise.all(\n\t\t\t\tArray.from(served, async (app) => {\n\t\t\t\t\tapp.entry.abortShutdownSignal();\n\t\t\t\t\tawait retire(app);\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t};\n}\n","import { createServer } from \"node:net\";\nimport type { Server } from \"node:net\";\n\nconst MAX_PORT = 65_535;\n\n/** Options for {@link listenFromPort}. */\nexport type ListenFromPortOptions = {\n\t/** The first port to try. 0 lets the OS pick one. */\n\tport: number;\n\t/** @default every interface */\n\thostname?: string | undefined;\n\t/** When true, a port in use throws and no other port is tried. */\n\tstrictPort: boolean;\n\t/** Runs for each port in use before the next port is tried. */\n\tonPortInUse?: (port: number) => void;\n\t/**\n\t * Runs when `strictPort` is true and the server listens on `hostname`, but\n\t * another server holds the port on a wildcard address.\n\t */\n\tonWildcardInUse?: (port: number) => void;\n};\n\n/**\n * Starts `server` on `port`. When the port is in use, it tries each next port\n * up to 65535, like Vite and `react-router-serve` do in development.\n *\n * @returns the port that the server listens on\n */\nexport async function listenFromPort(\n\tserver: Server,\n\t{ port, hostname, strictPort, onPortInUse, onWildcardInUse }: ListenFromPortOptions,\n): Promise<number> {\n\tif (port === 0) {\n\t\tawait bind(server, port, hostname);\n\t\treturn boundPort(server, port);\n\t}\n\tif (strictPort) {\n\t\t// Why a warning and not an error: a server on one other address also fails the wildcard\n\t\t// check, and that server does not share `hostname`. Vite warns for the same reason.\n\t\tconst freeOnWildcard = hostname == null || (await isFreeOnWildcard(port));\n\t\tawait bind(server, port, hostname);\n\t\tif (!freeOnWildcard) {\n\t\t\tonWildcardInUse?.(port);\n\t\t}\n\t\treturn port;\n\t}\n\tfor (let candidate = port; candidate <= MAX_PORT; candidate++) {\n\t\t// Why the wildcard check: a server on `::` and a server on `localhost` can share a port, and\n\t\t// then the browser can reach the other server.\n\t\tif (hostname == null || (await isFreeOnWildcard(candidate))) {\n\t\t\ttry {\n\t\t\t\tawait bind(server, candidate, hostname);\n\t\t\t\treturn candidate;\n\t\t\t} catch (error) {\n\t\t\t\tif (!isAddressInUse(error)) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tonPortInUse?.(candidate);\n\t}\n\tthrow new Error(`No open port from ${port} to ${MAX_PORT}.`);\n}\n\nasync function bind(server: Server, port: number, hostname: string | undefined): Promise<void> {\n\treturn new Promise<void>((resolve, reject) => {\n\t\tfunction onError(error: Error) {\n\t\t\tserver.off(\"listening\", onListening);\n\t\t\treject(error);\n\t\t}\n\t\tfunction onListening() {\n\t\t\tserver.off(\"error\", onError);\n\t\t\tresolve();\n\t\t}\n\t\tserver.once(\"error\", onError);\n\t\tserver.once(\"listening\", onListening);\n\t\tserver.listen(port, hostname);\n\t});\n}\n\nasync function isFreeOnWildcard(port: number): Promise<boolean> {\n\tconst probe = createServer();\n\ttry {\n\t\tawait bind(probe, port, undefined);\n\t} catch (error) {\n\t\tif (isAddressInUse(error)) {\n\t\t\treturn false;\n\t\t}\n\t\tthrow error;\n\t}\n\tawait new Promise<void>((resolve) => {\n\t\tprobe.close(() => {\n\t\t\tresolve();\n\t\t});\n\t});\n\treturn true;\n}\n\nfunction boundPort(server: Server, fallback: number): number {\n\tconst address = server.address();\n\treturn typeof address === \"object\" && address != null ? address.port : fallback;\n}\n\nfunction isAddressInUse(error: unknown): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === \"EADDRINUSE\";\n}\n","import { createServer as createHttpServer } from \"node:http\";\nimport type { Server } from \"node:http\";\nimport type { Plugin } from \"vite\";\nimport { asError, hookSink, textSink } from \"../core/log.js\";\nimport { devServerStage } from \"../node/dev-server.js\";\nimport { exitAfterFlush } from \"../node/exit.js\";\nimport { requestListener } from \"../node/response-writer.js\";\nimport { parsePort } from \"../node/tcp.js\";\nimport { SERVER_ENTRY_ID } from \"../vite/index.js\";\nimport { devUrlLines } from \"./dev-urls.js\";\nimport { loadEntry } from \"./load-entry.js\";\nimport { servedApps } from \"./served-apps.js\";\nimport { listenFromPort } from \"./start-port.js\";\n\n/**\n * Runs the app in development: the same pipeline as production, with Vite in\n * middleware mode inside it. Each request loads the server entry through\n * Vite's SSR runner, so an edit to a route or to the app's `server.ts` applies\n * at once. HMR shares the port. Vite's plugins get the CLI's HTTP server as\n * `server.httpServer`.\n *\n * The port is `--port`, else `PORT`, else Vite's `server.port`. When that port is in use, the\n * server tries each next port, unless Vite's `server.strictPort` is true. The\n * host is `HOST`, else Vite's `server.host`.\n */\nexport async function start(): Promise<void> {\n\tconst vite = await import(\"vite\");\n\tconst httpServer = createHttpServer();\n\tconst viteServer = await vite.createServer({\n\t\t// Why `true`, not `{ server }`: Vite then adds a proxy `upgrade` listener to the server, and a\n\t\t// restart does not remove it.\n\t\tserver: { middlewareMode: true, ws: { server: httpServer } },\n\t\tappType: \"custom\",\n\t\tplugins: [shareHttpServer(httpServer)],\n\t});\n\t// Why read it for each request: a Vite restart, such as after a config edit, replaces the environments.\n\tconst ssrRunner = () => {\n\t\tconst { ssr } = viteServer.environments;\n\t\tif (ssr == null || !vite.isRunnableDevEnvironment(ssr)) {\n\t\t\tthrow new Error(\"Vite's SSR environment cannot run modules.\");\n\t\t}\n\t\treturn ssr.runner;\n\t};\n\tssrRunner();\n\tif (!viteServer.config.plugins.some((plugin) => plugin.name === \"@ngrok/app-server\")) {\n\t\tawait viteServer.close();\n\t\tthrow new Error(\n\t\t\t\"`app-server start` needs the `appServer` plugin from @ngrok/app-server/vite in the Vite config.\",\n\t\t);\n\t}\n\tconst devServer = devServerStage(viteServer.middlewares, {\n\t\tpublicFiles: () => ({ directory: viteServer.config.publicDir, base: viteServer.config.base }),\n\t});\n\tconst sink = hookSink(textSink());\n\tconst apps = servedApps();\n\n\tconst listener = requestListener(async (request, bindings) => {\n\t\ttry {\n\t\t\treturn await apps.serve(\n\t\t\t\tawait loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)),\n\t\t\t\tasync (entry) => entry.fetchDev(request, bindings, devServer),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tviteServer.ssrFixStacktrace(error);\n\t\t\t}\n\t\t\tsink.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tmessage: \"dev request failed\",\n\t\t\t\tattributes: { error: asError(error) },\n\t\t\t});\n\t\t\treturn new Response(error instanceof Error ? (error.stack ?? error.message) : String(error), {\n\t\t\t\tstatus: 500,\n\t\t\t\theaders: { \"Content-Type\": \"text/plain; charset=utf-8\" },\n\t\t\t});\n\t\t}\n\t});\n\thttpServer.on(\"request\", (request, response) => {\n\t\tvoid listener(request, response);\n\t});\n\n\tconst port =\n\t\tprocess.env.PORT == null ? viteServer.config.server.port : parsePort(process.env.PORT);\n\tconst hostname = process.env.HOST || viteHostname(viteServer.config.server.host);\n\tconst boundPort = await listenFromPort(httpServer, {\n\t\tport,\n\t\thostname,\n\t\tstrictPort: viteServer.config.server.strictPort,\n\t\tonPortInUse: (inUse) => {\n\t\t\tsink.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tmessage: \"port in use, trying the next port\",\n\t\t\t\tattributes: { \"server.port\": inUse },\n\t\t\t});\n\t\t},\n\t\tonWildcardInUse: (inUse) => {\n\t\t\tsink.log({\n\t\t\t\tlevel: \"warn\",\n\t\t\t\tmessage: \"port in use on a wildcard address\",\n\t\t\t\tattributes: {\n\t\t\t\t\t\"server.port\": inUse,\n\t\t\t\t\t\"server.address\": hostname,\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\t// Why Vite's logger: the lines then follow the app's `logLevel` and `customLogger`, as in `vite dev`.\n\tviteServer.config.logger.info(\"\");\n\tfor (const line of devUrlLines({ hostname, port: boundPort, base: viteServer.config.base })) {\n\t\tviteServer.config.logger.info(line);\n\t}\n\n\tfor (const signal of [\"SIGTERM\", \"SIGINT\"] as const) {\n\t\tprocess.once(signal, () => {\n\t\t\tconst pluginsStopped = apps.stopAll();\n\t\t\thttpServer.closeAllConnections();\n\t\t\tconst httpClosed = new Promise<void>((resolve) => {\n\t\t\t\thttpServer.close(() => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst viteClosed = viteServer.close().catch((error: unknown) => {\n\t\t\t\tsink.log({\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tmessage: \"Vite close failed\",\n\t\t\t\t\tattributes: { error: asError(error) },\n\t\t\t\t});\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t});\n\t\t\tvoid Promise.all([pluginsStopped, httpClosed, viteClosed]).finally(exitAfterFlush);\n\t\t});\n\t}\n}\n\n/**\n * A Vite plugin that sets `server.httpServer` to the CLI's HTTP server before\n * the `configureServer` hooks of the app's plugins run. Why: in middleware\n * mode, Vite sets it to `null`. Then a plugin that waits for `listening` or\n * `close` on it does nothing, with no error.\n *\n * @example\n * vite.createServer({ plugins: [shareHttpServer(httpServer)] });\n */\nfunction shareHttpServer(httpServer: Server): Plugin {\n\tconst plugin: Plugin = {\n\t\tname: \"@ngrok/app-server:http-server\",\n\t\t// Why first: Vite puts an inline plugin after the config file's plugins, so an app plugin with\n\t\t// `enforce: \"pre\"` and `order: \"pre\"` runs its `configureServer` before this one.\n\t\tconfigResolved: (config) => {\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Vite sorts each hook from this array later.\n\t\t\tconst plugins = config.plugins as Plugin[];\n\t\t\tplugins.splice(plugins.indexOf(plugin), 1);\n\t\t\tplugins.unshift(plugin);\n\t\t},\n\t\tconfigureServer: {\n\t\t\torder: \"pre\",\n\t\t\thandler: (server) => {\n\t\t\t\tserver.httpServer = httpServer;\n\t\t\t},\n\t\t},\n\t};\n\treturn plugin;\n}\n\n/** The hostname for Vite's `server.host`: `true` is every interface, and no value is `localhost`. */\nfunction viteHostname(host: string | boolean | undefined): string | undefined {\n\tif (host === true) {\n\t\treturn undefined;\n\t}\n\treturn typeof host === \"string\" && host !== \"\" ? host : \"localhost\";\n}\n"],"mappings":";;;;;;;;;;;;;AAIA,MAAM,gCAAgB,IAAI,IAAI;CAAC;CAAI;CAAW;AAAI,CAAC;AACnD,MAAM,gCAAgB,IAAI,IAAI;CAAC;CAAa;CAAa;AAAK,CAAC;;;;;;;;;AAY/D,SAAgB,YACf,EAAE,UAAU,MAAM,QAClB,aAAa,kBAAkB,GACpB;CACX,MAAM,SAAS,SAAiB,GAAG,YAAY,MAAM,IAAI,CAAC,CAAC,MAAM,GAAG,EAAE,IAAI;CAC1E,MAAM,YAAY,OAAO,QAAQ,UAAU,CAAC,CAAC,SAAS,CAAC,MAAM,UAAU,CAAC,OACvE,QAAQ,KAAK,EAAE,SAAS,cAAc;EAAE;EAAM;EAAS;CAAO,EAAE,CACjE;CAEA,MAAM,OACL,YAAY,QAAQ,cAAc,IAAI,QAAQ,IAC3C,CACA;EAAE,OAAO;EAAM,KAAK,MAAM,WAAW;EAAG,eAAe;CAAU,GACjE,GAAG,UACD,QAAQ,EAAE,SAAS,aAAa,WAAW,UAAU,YAAY,WAAW,CAAC,CAC7E,KAAK,EAAE,MAAM,eAAe;EAC5B,OAAO;EACP,KAAK,MAAM,OAAO;EAClB,eAAe;CAChB,EAAE,CACJ,IACC,CACA;EACC,OAAO,cAAc,IAAI,QAAQ;EACjC,KAAK,MAAM,QAAQ;EACnB,eAAe,UAAU,MAAM,EAAE,cAAc,YAAY,QAAQ,CAAC,EAAE;CACvE,CACD;CACH,MAAM,QAAQ,KAAK,IAAI,GAAG,GAAG,KAAK,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,UAAU,IAAI,M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GAC/D,KAAK,IAAI;IACR,OAAO;IACP,SAAS;IACT,YAAY,EAAE,OAAO,QAAQ,KAAK,EAAE;GACrC,CAAC;GACD,QAAQ,WAAW;EACpB,CAAC;EACD,AAAK,QAAQ,IAAI;GAAC;GAAgB;GAAY;EAAU,CAAC,CAAC,CAAC,QAAQ,cAAc;CAClF,CAAC;AAEH;;;;;;;;;;AAWA,SAAS,gBAAgB,YAA4B;CACpD,MAAM,SAAiB;EACtB,MAAM;EAGN,iBAAiB,WAAW;GAE3B,MAAM,UAAU,OAAO;GACvB,QAAQ,OAAO,QAAQ,QAAQ,MAAM,GAAG,CAAC;GACzC,QAAQ,QAAQ,MAAM;EACvB;EACA,iBAAiB;GAChB,OAAO;GACP,UAAU,WAAW;IACpB,OAAO,aAAa;GACrB;EACD;CACD;CACA,OAAO;AACR;;AAGA,SAAS,aAAa,MAAwD;CAC7E,IAAI,SAAS,MACZ;CAED,OAAO,OAAO,SAAS,YAAY,SAAS,KAAK,OAAO;AACzD"}
|
package/dist/tanstack-start.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as TrailingSlash } from "./trailing-slash-
|
|
1
|
+
import { _ as Mode, a as FrameworkRuntime } from "./types-C_I3i62n.js";
|
|
2
|
+
import { t as TrailingSlash } from "./trailing-slash-D_52DJaQ.js";
|
|
3
3
|
import { AnyRouter, RegisteredRouter } from "@tanstack/react-router";
|
|
4
4
|
/**
|
|
5
5
|
* The `trailingSlash` mode of a TanStack router: the app's registered router
|
package/dist/tanstack-start.js
CHANGED
|
@@ -33,10 +33,10 @@ function tcp({ port, host, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS } = {}) {
|
|
|
33
33
|
};
|
|
34
34
|
if ("Bun" in globalThis) return (await import("./bun-BCz6K_Xv.js")).listen(fetch, options);
|
|
35
35
|
if ("Deno" in globalThis) return (await import("./deno-aqhikNMG.js")).listen(fetch, options);
|
|
36
|
-
return (await import("./node-
|
|
36
|
+
return (await import("./node-DBwgrye_.js")).listen(fetch, options);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export { tcp as n, parsePort as t };
|
|
42
|
-
//# sourceMappingURL=tcp-
|
|
42
|
+
//# sourceMappingURL=tcp-B8aFGQRB.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcp-
|
|
1
|
+
{"version":3,"file":"tcp-B8aFGQRB.js","names":[],"sources":["../src/node/tcp.ts"],"sourcesContent":["import type { Listener } from \"../core/types.js\";\n\n/** Above the ngrok edge's 90 s idle pool, so the edge never reuses a socket that the server is closing. */\nconst DEFAULT_IDLE_TIMEOUT_MS = 95_000;\n\n/** Options for {@link tcp}. */\nexport type TcpOptions = {\n\t/** @default the `PORT` environment variable, else 3000 */\n\tport?: number;\n\t/** @default the `HOST` environment variable, else every interface */\n\thost?: string;\n\t/** @default 95000 */\n\tidleTimeoutMs?: number;\n};\n\n/**\n * Reads a port number. A value that is not an integer from 0 to 65535 throws,\n * so a bad `PORT` stops startup.\n *\n * @example\n * parsePort(\"8080\"); // => 8080\n */\nexport function parsePort(value: string): number {\n\tconst port = Number(value);\n\tif (value.trim() === \"\" || !Number.isInteger(port) || port < 0 || port > 65_535) {\n\t\tthrow new Error(`PORT must be an integer from 0 to 65535, not \"${value}\".`);\n\t}\n\treturn port;\n}\n\n/**\n * The default listener: a TCP port, served by the runtime's own HTTP server\n * (`node:http` on Node, `Bun.serve` on Bun, `Deno.serve` on Deno). It reads\n * `PORT` and `HOST` when it starts.\n *\n * @example\n * createServer({ listeners: [tcp({ port: 8080 })] });\n */\nexport function tcp({\n\tport,\n\thost,\n\tidleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS,\n}: TcpOptions = {}): Listener {\n\treturn {\n\t\tname: \"tcp\",\n\t\tstart: async (fetch, { trustForwardedProto = false } = {}) => {\n\t\t\tconst options = {\n\t\t\t\tport: port ?? (process.env.PORT == null ? 3000 : parsePort(process.env.PORT)),\n\t\t\t\thostname: host ?? (process.env.HOST || undefined),\n\t\t\t\tidleTimeoutMs,\n\t\t\t\ttrustForwardedProto,\n\t\t\t};\n\t\t\tif (\"Bun\" in globalThis) {\n\t\t\t\treturn (await import(\"./runtimes/bun.js\")).listen(fetch, options);\n\t\t\t}\n\t\t\tif (\"Deno\" in globalThis) {\n\t\t\t\treturn (await import(\"./runtimes/deno.js\")).listen(fetch, options);\n\t\t\t}\n\t\t\treturn (await import(\"./runtimes/node.js\")).listen(fetch, options);\n\t\t},\n\t};\n}\n"],"mappings":";;AAGA,MAAM,0BAA0B;;;;;;;;AAmBhC,SAAgB,UAAU,OAAuB;CAChD,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,MAAM,KAAK,MAAM,MAAM,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,OACxE,MAAM,IAAI,MAAM,iDAAiD,MAAM,GAAG;CAE3E,OAAO;AACR;;;;;;;;;AAUA,SAAgB,IAAI,EACnB,MACA,MACA,gBAAgB,4BACD,CAAC,GAAa;CAC7B,OAAO;EACN,MAAM;EACN,OAAO,OAAO,OAAO,EAAE,sBAAsB,UAAU,CAAC,MAAM;GAC7D,MAAM,UAAU;IACf,MAAM,SAAS,QAAQ,IAAI,QAAQ,OAAO,MAAO,UAAU,QAAQ,IAAI,IAAI;IAC3E,UAAU,SAAS,QAAQ,IAAI,QAAQ;IACvC;IACA;GACD;GACA,IAAI,SAAS,YACZ,QAAQ,MAAM,OAAO,qBAAoB,CAAE,OAAO,OAAO,OAAO;GAEjE,IAAI,UAAU,YACb,QAAQ,MAAM,OAAO,sBAAqB,CAAE,OAAO,OAAO,OAAO;GAElE,QAAQ,MAAM,OAAO,sBAAqB,CAAE,OAAO,OAAO,OAAO;EAClE;CACD;AACD"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AppServer } from "./create-server-
|
|
1
|
+
import { a as FrameworkRuntime, y as RequestContext } from "./types-C_I3i62n.js";
|
|
2
|
+
import { t as AppServer } from "./create-server-DKJ0wASH.js";
|
|
3
3
|
/** Options for {@link createTestServer}. */
|
|
4
4
|
export type TestServerOptions = {
|
|
5
5
|
/**
|
package/dist/testing.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as requestLogger } from "./log-CW_g1pWk.js";
|
|
2
|
+
import { o as withRequestContext$1 } from "./request-context-BdAH1D-2.js";
|
|
3
3
|
import { t as BUILD_MANIFEST_FILE } from "./build-manifest-DBMWe3Lx.js";
|
|
4
|
-
import { t as createEntry } from "./entry-
|
|
5
|
-
import { t as host } from "./node-
|
|
4
|
+
import { t as createEntry } from "./entry-BSbsQ_kq.js";
|
|
5
|
+
import { t as host } from "./node-DiMwdTOC.js";
|
|
6
6
|
import { n as scriptHashesOf } from "./script-hashes-CU7P9oZU.js";
|
|
7
7
|
import { Context } from "hono";
|
|
8
8
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as Plugin } from "./types-C_I3i62n.js";
|
|
2
2
|
/**
|
|
3
3
|
* How a page URL ends:
|
|
4
4
|
*
|
|
@@ -33,4 +33,4 @@ type TrailingSlashOptions = {
|
|
|
33
33
|
*/
|
|
34
34
|
declare function trailingSlash({ mode }: TrailingSlashOptions): Plugin;
|
|
35
35
|
export { TrailingSlashOptions as n, trailingSlash as r, TrailingSlash as t };
|
|
36
|
-
//# sourceMappingURL=trailing-slash-
|
|
36
|
+
//# sourceMappingURL=trailing-slash-D_52DJaQ.d.ts.map
|
|
@@ -62,9 +62,37 @@ type LogLevel = "debug" | "info" | "warn" | "error";
|
|
|
62
62
|
* {@link jsonSink}. Attribute names are flat and dotted, such as `http.method`.
|
|
63
63
|
*/
|
|
64
64
|
type LogSink = {
|
|
65
|
-
log: (
|
|
65
|
+
log: (line: LogLine) => void;
|
|
66
66
|
};
|
|
67
|
-
/**
|
|
67
|
+
/** One log line. Attribute names are flat and dotted, such as `http.method`. */
|
|
68
|
+
type LogLine = {
|
|
69
|
+
level: LogLevel;
|
|
70
|
+
message: string;
|
|
71
|
+
attributes: Readonly<Record<string, unknown>>;
|
|
72
|
+
};
|
|
73
|
+
/** Hooks that change each log line before it goes to the {@link LogSink}. */
|
|
74
|
+
type LogOptions = {
|
|
75
|
+
/**
|
|
76
|
+
* Gives the attributes of each line, after the server flattens each error.
|
|
77
|
+
* Use it to add, change, or remove a field, such as to redact a value.
|
|
78
|
+
*/
|
|
79
|
+
attributes?: (line: LogLine) => Readonly<Record<string, unknown>>;
|
|
80
|
+
/**
|
|
81
|
+
* Gives the fields of an attribute whose value is an `Error`. `prefix` is
|
|
82
|
+
* the attribute name, such as `error`. `fields` holds the default fields,
|
|
83
|
+
* so the hook can change some of them and keep the rest.
|
|
84
|
+
*/
|
|
85
|
+
error?: (value: {
|
|
86
|
+
error: Error;
|
|
87
|
+
prefix: string;
|
|
88
|
+
fields: Readonly<Record<string, unknown>>;
|
|
89
|
+
}) => Readonly<Record<string, unknown>>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A logger with one method for each level. The logger of a request adds the
|
|
93
|
+
* request ID, method, and path to each line. These fields win over a field
|
|
94
|
+
* of the same name that the caller gives.
|
|
95
|
+
*/
|
|
68
96
|
type RequestLogger = Record<LogLevel, (message: string, attributes?: Readonly<Record<string, unknown>>) => void>;
|
|
69
97
|
/** What {@link requestContext} gives for the request that runs. */
|
|
70
98
|
type RequestContext = {
|
|
@@ -409,5 +437,5 @@ type ListenerStartOptions = {
|
|
|
409
437
|
*/
|
|
410
438
|
trustForwardedProto?: boolean;
|
|
411
439
|
};
|
|
412
|
-
export {
|
|
413
|
-
//# sourceMappingURL=types-
|
|
440
|
+
export { SentResponse as C, StaticFiles as D, StartedListener as E, ResponseEdge as O, ResponseHeaders as S, SetupInfo as T, Mode as _, FrameworkRuntime as a, RequestLogger as b, HostRuntime as c, ListenerBindings as d, ListenerStartOptions as f, LogSink as g, LogOptions as h, FileInfo as i, Lifecycle as l, LogLine as m, ByteRange as n, FrameworkRuntimeFactory as o, LogLevel as p, FetchHandler as r, HeaderHook as s, AppServerEnv as t, Listener as u, Plugin as v, ServerBindings as w, RequestStore as x, RequestContext as y };
|
|
441
|
+
//# sourceMappingURL=types-C_I3i62n.d.ts.map
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as HostRuntime } from "./types-
|
|
2
|
-
import { t as AppServerEntry } from "./entry-
|
|
1
|
+
import { c as HostRuntime } from "./types-C_I3i62n.js";
|
|
2
|
+
import { t as AppServerEntry } from "./entry-C9bBcYeP.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
|
package/dist/vercel.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as flushLogs } from "./log-
|
|
2
|
-
import { i as withForwardedProto } from "./create-server-
|
|
3
|
-
import { t as host$1 } from "./node-
|
|
4
|
-
import { t as requestListener } from "./response-writer-
|
|
1
|
+
import { n as flushLogs } from "./log-CW_g1pWk.js";
|
|
2
|
+
import { i as withForwardedProto } from "./create-server-C63luLkn.js";
|
|
3
|
+
import { t as host$1 } from "./node-DiMwdTOC.js";
|
|
4
|
+
import { t as requestListener } from "./response-writer-CLtCseu5.js";
|
|
5
5
|
import { n as brotliOnlyFiles } from "./brotli-only-DrA29Ecw.js";
|
|
6
6
|
|
|
7
7
|
// src/vercel/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/app-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A composable Hono app server for React Router and TanStack Start: prerendered pages, streamed compression, structured logs, and clean shutdown on Node, Bun, Deno, and Vercel.",
|
|
5
5
|
"homepage": "https://github.com/ngrok/app-server#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compress-CO0Nwc8x.js","names":[],"sources":["../src/node/compress.ts"],"sourcesContent":["import type { Transform } from \"node:stream\";\nimport {\n\tbrotliCompressSync,\n\tconstants,\n\tcrc32,\n\tcreateBrotliCompress,\n\tcreateDeflateRaw,\n\tcreateGzip,\n} from \"node:zlib\";\n\n/**\n * A stream from {@link gzipStream} or {@link brotliStream}. Why a class: the\n * node response writer reads `busy` to hold the head for zlib's first chunk,\n * and a field costs less than a `WeakMap` entry for each response.\n */\nclass ZlibBody extends ReadableStream<Uint8Array> {\n\t/** Whether the next chunk waits only on zlib, because the source gave the bytes already. */\n\tpublic busy = false;\n}\n\n/**\n * Whether the next chunk of `stream` waits only on zlib, because its source\n * gave the bytes already. It gives `undefined` for a stream that is not from\n * {@link gzipStream} or {@link brotliStream}.\n *\n * @example\n * waitsForZlib(gzipStream(source)); // => false, until the first read gives zlib a chunk\n */\nexport function waitsForZlib(stream: ReadableStream<Uint8Array>): boolean | undefined {\n\treturn stream instanceof ZlibBody ? stream.busy : undefined;\n}\n\n/**\n * The gzip header (RFC 1952): the magic number, deflate, no flags, no time,\n * and the Unix system code.\n */\nconst HEADER = Buffer.from([31, 139, 8, 0, 0, 0, 0, 0, 0, 3]);\n\n/** The gzip member of an empty body: the header, a final empty block, a CRC-32 of 0, and a size of 0. */\nconst EMPTY_MEMBER = Buffer.concat([HEADER, Buffer.from([3, 0, 0, 0, 0, 0, 0, 0, 0, 0])]);\n\n/**\n * The largest body that a pooled gzip or brotli stream compresses. Why a\n * limit: above about 64 KiB, the CRC-32 of a gzip body on the main thread\n * costs more than a new zlib stream does.\n */\nconst POOLED_MAX_BYTES = 64 * 1024;\n\n/** The most zlib streams that wait for a body in each pool. Why a limit: an idle deflate stream keeps about 276 KiB of zlib state. */\nconst MAX_IDLE = 16;\n\nfunction ignore(): void {}\n\n/**\n * A zlib stream that compresses one body at a time, the target of its output\n * and of its failure, and the size of the longest body that it compressed.\n */\ntype Pooled = {\n\tstream: Transform;\n\toutput: (chunk: Buffer) => void;\n\tfail: (error: Error) => void;\n\tsize: number;\n};\n\n/** The idle zlib streams of one encoding, the last one given back last. */\ntype Pool = {\n\t/** A new zlib stream that finishes its output with each write. */\n\tcreate: () => Transform;\n\tidle: Pooled[];\n\t/**\n\t * Whether a reset keeps state of the earlier bodies, so a stream records\n\t * the size of its longest body (see {@link take}).\n\t */\n\tsized: boolean;\n\t/** Whether a reset lets the stream compress the next body. Else each body gets a new stream. */\n\treuses: boolean;\n};\n\nfunction newPooled(pool: Pool): Pooled {\n\tconst pooled: Pooled = { stream: pool.create(), output: ignore, fail: ignore, size: 0 };\n\tpooled.stream.on(\"data\", (chunk: Buffer) => {\n\t\tpooled.output(chunk);\n\t});\n\t// Why both: zlib destroys the stream at a failure, and then it never calls the write callback.\n\tpooled.stream.on(\"error\", (error) => {\n\t\tpooled.fail(error);\n\t});\n\tpooled.stream.on(\"close\", () => {\n\t\t// Why the check: a stream that the pool destroys has no body, and an error costs its stack.\n\t\tif (pooled.fail !== ignore) {\n\t\t\tpooled.fail(new Error(\"The zlib stream closed.\"));\n\t\t}\n\t});\n\treturn pooled;\n}\n\n/**\n * The deflate pool. Why `Z_FINISH`: when the output fills the buffer of the\n * stream exactly, the stream calls zlib again, and a sync flush then adds an\n * empty block. So the output would depend on earlier bodies.\n */\nconst DEFLATE_POOL: Pool = {\n\tcreate: () => createDeflateRaw({ flush: constants.Z_FINISH }),\n\tidle: [],\n\tsized: true,\n\treuses: true,\n};\n\n/**\n * The brotli quality of a response. Why 4: for HTML, its output is smaller\n * than gzip level 6, for the same CPU time. The `compression` middleware of\n * Express also uses 4.\n */\nconst BROTLI_QUALITY = 4;\n\n/**\n * The base-2 logarithm of the brotli window, 256 KiB. Why not the default\n * of 22 (4 MiB): Node.js tells V8 the full size of each encoder's ring\n * buffer as external memory, and at 32 open encoders V8 then runs a full\n * garbage collection for every few responses. A page under 256 KiB gets\n * the same bytes, and a page of 2.7 MB gets 5% more.\n */\nconst BROTLI_WINDOW_BITS = 18;\n\nconst BROTLI_PARAMS = {\n\t[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,\n\t[constants.BROTLI_PARAM_QUALITY]: BROTLI_QUALITY,\n\t[constants.BROTLI_PARAM_LGWIN]: BROTLI_WINDOW_BITS,\n};\n\n/**\n * The brotli pool. Why not sized: a reset makes a new brotli encoder with the\n * same parameters, so the output of a body never depends on an earlier one.\n */\nconst BROTLI_POOL: Pool = {\n\tcreate: () =>\n\t\tcreateBrotliCompress({ flush: constants.BROTLI_OPERATION_FINISH, params: BROTLI_PARAMS }),\n\tidle: [],\n\tsized: false,\n\t// Why not on Bun or Deno: after a reset, a Bun encoder forgets its quality, and a Deno encoder gives no bytes.\n\treuses: !(\"Bun\" in globalThis) && !(\"Deno\" in globalThis),\n};\n\n/**\n * An idle stream of `pool` for a body of `size` bytes, else a new one. It\n * takes a stream whose bodies were each no longer than this one: the longest\n * such, and of those the last one given back, whose memory is still in the\n * cache.\n *\n * Why for deflate: a reset keeps the window of zlib, and zlib reads the bytes\n * after the end of a body to hash and match its last bytes. After a longer\n * body, these are bytes of that body, so they could change the output of this\n * one. A stream whose bodies were no longer has only the zeros that zlib\n * writes after each body there, as a new stream does.\n */\nfunction take(pool: Pool, size: number): Pooled {\n\tconst { idle } = pool;\n\tlet best = -1;\n\tlet bestSize = -1;\n\tfor (let index = idle.length - 1; index >= 0; index -= 1) {\n\t\tconst each = idle[index]?.size ?? Infinity;\n\t\tif (each <= size && each > bestSize) {\n\t\t\tbest = index;\n\t\t\tbestSize = each;\n\t\t}\n\t}\n\tif (best === -1) {\n\t\treturn newPooled(pool);\n\t}\n\tconst taken = idle[best];\n\tconst last = idle.pop();\n\tif (taken == null || last == null) {\n\t\treturn newPooled(pool);\n\t}\n\t// Why move the last one into the gap: the order of the others does not matter, and it costs no copy.\n\tif (last !== taken) {\n\t\tidle[best] = last;\n\t}\n\treturn taken;\n}\n\n/**\n * Gives back a stream of `pool` after its body. Why reset: the next body must\n * not use the bytes of this one as a dictionary. When the pool is full, it\n * keeps the streams of the shortest bodies, which more bodies can take.\n */\nfunction release(pool: Pool, pooled: Pooled): void {\n\tpooled.output = ignore;\n\tpooled.fail = ignore;\n\tconst { stream } = pooled;\n\t// Why check the queues: a stream with output or input still queued would give it to the next body.\n\tif (\n\t\t!pool.reuses ||\n\t\tstream.destroyed ||\n\t\tstream.readableLength !== 0 ||\n\t\tstream.writableLength !== 0\n\t) {\n\t\tstream.destroy();\n\t\treturn;\n\t}\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- each pool creates a zlib stream, which has `reset`.\n\t(stream as Transform & { reset: () => void }).reset();\n\t// Why the check: a reset that fails destroys the stream.\n\tif (stream.destroyed) {\n\t\treturn;\n\t}\n\tconst { idle } = pool;\n\tif (idle.length < MAX_IDLE) {\n\t\tidle.push(pooled);\n\t\treturn;\n\t}\n\tlet longest = 0;\n\tfor (let index = 1; index < idle.length; index += 1) {\n\t\tif ((idle[index]?.size ?? 0) > (idle[longest]?.size ?? 0)) {\n\t\t\tlongest = index;\n\t\t}\n\t}\n\tconst evicted = idle[longest];\n\tif (evicted != null && evicted.size > pooled.size) {\n\t\tidle[longest] = pooled;\n\t\tevicted.stream.destroy();\n\t} else {\n\t\tstream.destroy();\n\t}\n}\n\n/** Writes `chunk` to `stream`. zlib gives all the output of the chunk before this resolves. */\nasync function write(stream: Transform, chunk: Uint8Array): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tstream.write(chunk, (error) => {\n\t\t\tif (error == null) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t});\n}\n\n/**\n * The output of a stream of `pool` for a body of one chunk, in one zlib call.\n * `use` gets the stream while zlib compresses, so a cancel can destroy it,\n * and gets `undefined` before the stream goes back to the pool. Why only a\n * body of one chunk: a deflate reset keeps the old window, and a second write\n * reads its bytes as history. The output of one write is the same as from a\n * new stream, so it does not depend on an earlier body.\n */\nasync function compressOnce(\n\tpool: Pool,\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer[]> {\n\tconst pooled = take(pool, value.byteLength);\n\tuse(pooled);\n\tconst parts: Buffer[] = [];\n\tpooled.output = (chunk) => {\n\t\tparts.push(chunk);\n\t};\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tpooled.fail = reject;\n\t\t\tpooled.stream.write(value, (error) => {\n\t\t\t\tif (error != null) {\n\t\t\t\t\treject(error);\n\t\t\t\t} else if (pooled.stream.destroyed) {\n\t\t\t\t\treject(new Error(\"The zlib stream closed.\"));\n\t\t\t\t} else {\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t} catch (error) {\n\t\tpooled.output = ignore;\n\t\tpooled.fail = ignore;\n\t\tpooled.stream.destroy();\n\t\tthrow error;\n\t}\n\tif (pool.sized) {\n\t\tpooled.size = Math.max(pooled.size, value.byteLength);\n\t}\n\t// Why first: a cancel after this must not destroy a stream that the pool gives to another body.\n\tuse(undefined);\n\trelease(pool, pooled);\n\treturn parts;\n}\n\n/**\n * The gzip member of a body of one chunk: the raw deflate output of a pooled\n * stream, with the header and the trailer written here.\n */\nasync function gzipOnce(\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer> {\n\tconst parts = await compressOnce(DEFLATE_POOL, value, use);\n\tconst trailer = Buffer.allocUnsafe(8);\n\ttrailer.writeUInt32LE(crc32(value), 0);\n\ttrailer.writeUInt32LE(value.byteLength, 4);\n\treturn Buffer.concat([HEADER, ...parts, trailer]);\n}\n\n/** The brotli stream of a body of one chunk, from a pooled encoder. */\nasync function brotliOnce(\n\tvalue: Uint8Array,\n\tuse: (pooled: Pooled | undefined) => void,\n): Promise<Buffer> {\n\treturn Buffer.concat(await compressOnce(BROTLI_POOL, value, use));\n}\n\n/** How {@link zlibStream} compresses a body. */\ntype Codec = {\n\t/** A new zlib stream that flushes after each write. */\n\tcreate: () => Transform;\n\t/** The output for a body with no bytes. */\n\tempty: Buffer;\n\t/**\n\t * The output for a body of one chunk, up to 64 KiB, with no new zlib\n\t * stream. `use` gets the zlib stream while it compresses.\n\t */\n\tonce: (value: Uint8Array, use: (pooled: Pooled | undefined) => void) => Promise<Buffer>;\n};\n\n/**\n * Compresses a byte stream with `codec`. Each written chunk is readable at\n * once. It reads the next source chunk only when the consumer pulls, so a\n * slow client holds back the source. When the source ends by the time zlib\n * finishes a chunk, that chunk and the end of the stream go out as one. Why:\n * the host writes each chunk to the socket on its own, and a write costs more\n * than its few bytes.\n */\nfunction zlibStream(source: ReadableStream<Uint8Array>, codec: Codec): ReadableStream<Uint8Array> {\n\tconst reader = source.getReader();\n\tlet ended = false;\n\tconst markEnded = () => {\n\t\tended = true;\n\t};\n\t// Why a flag: after each zlib write, it tells with no read whether the source ended meanwhile.\n\tvoid reader.closed.then(markEnded, () => {});\n\t/** The zlib stream of a body of more than one chunk. */\n\tlet zlib: Transform | undefined;\n\t/** The pooled zlib stream while it compresses the one chunk of a body. */\n\tlet pooled: Pooled | undefined;\n\tlet started = false;\n\t/** The zlib output that waits for the next enqueue. */\n\tlet held: Buffer[] = [];\n\tlet heldBytes = 0;\n\tconst enqueueHeld = (controller: ReadableStreamDefaultController<Uint8Array>) => {\n\t\tconst [first] = held;\n\t\tif (first == null) {\n\t\t\treturn;\n\t\t}\n\t\t// Why no copy for one chunk: zlib gives each chunk its own bytes, and it never writes them again.\n\t\tcontroller.enqueue(held.length === 1 ? first : Buffer.concat(held));\n\t\theld = [];\n\t\theldBytes = 0;\n\t};\n\tconst startZlib = (\n\t\tbody: ZlibBody,\n\t\tcontroller: ReadableStreamDefaultController<Uint8Array>,\n\t): Transform => {\n\t\tconst created = codec.create();\n\t\tcreated.on(\"data\", (chunk: Buffer) => {\n\t\t\theld.push(chunk);\n\t\t\theldBytes += chunk.byteLength;\n\t\t\t// Why: the output of a large source chunk goes out while zlib still compresses the rest.\n\t\t\tif (heldBytes >= constants.Z_DEFAULT_CHUNK) {\n\t\t\t\tenqueueHeld(controller);\n\t\t\t}\n\t\t});\n\t\tcreated.on(\"end\", () => {\n\t\t\tbody.busy = false;\n\t\t\tenqueueHeld(controller);\n\t\t\tcontroller.close();\n\t\t});\n\t\tcreated.on(\"error\", (error) => {\n\t\t\tbody.busy = false;\n\t\t\tcontroller.error(error);\n\t\t});\n\t\treturn created;\n\t};\n\tconst stream: ZlibBody = new ZlibBody(\n\t\t{\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tlet chunk = await reader.read();\n\t\t\t\t\t// Why skip empty chunks: zlib writes nothing for one, and a pull that enqueues nothing\n\t\t\t\t\t// is not called again.\n\t\t\t\t\twhile (!chunk.done && chunk.value.byteLength === 0) {\n\t\t\t\t\t\tchunk = await reader.read();\n\t\t\t\t\t}\n\t\t\t\t\tif (!started) {\n\t\t\t\t\t\tstarted = true;\n\t\t\t\t\t\tif (chunk.done) {\n\t\t\t\t\t\t\tcontroller.enqueue(codec.empty);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstream.busy = true;\n\t\t\t\t\t\t// Why wait: a source that closes in the pull that gave this chunk ends one microtask later.\n\t\t\t\t\t\tawait Promise.resolve();\n\t\t\t\t\t\tif (ended && chunk.value.byteLength <= POOLED_MAX_BYTES) {\n\t\t\t\t\t\t\tconst output = await codec.once(chunk.value, (each) => {\n\t\t\t\t\t\t\t\tpooled = each;\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tstream.busy = false;\n\t\t\t\t\t\t\tcontroller.enqueue(output);\n\t\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tzlib ??= startZlib(stream, controller);\n\t\t\t\t\tstream.busy = true;\n\t\t\t\t\tif (chunk.done) {\n\t\t\t\t\t\tzlib.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait write(zlib, chunk.value);\n\t\t\t\t\tif (ended) {\n\t\t\t\t\t\tzlib.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tstream.busy = false;\n\t\t\t\t\t// Why the output is here: zlib emits the output of a chunk before it calls the write\n\t\t\t\t\t// callback, so this pull enqueues a chunk and the consumer's read does not wait.\n\t\t\t\t\tenqueueHeld(controller);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tstream.busy = false;\n\t\t\t\t\tzlib?.destroy();\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t\t// Why cancel the source: a client disconnect must reach the handler, so it stops its work.\n\t\t\tasync cancel(reason) {\n\t\t\t\tzlib?.destroy();\n\t\t\t\t// Why destroy: a stream that a write still uses must never go back to the pool.\n\t\t\t\tpooled?.stream.destroy();\n\t\t\t\treturn reader.cancel(reason);\n\t\t\t},\n\t\t},\n\t\t// Why 0: the stream reads its source only when the consumer reads.\n\t\t{ highWaterMark: 0 },\n\t);\n\treturn stream;\n}\n\nconst GZIP: Codec = {\n\tcreate: () => createGzip({ flush: constants.Z_SYNC_FLUSH }),\n\tempty: EMPTY_MEMBER,\n\tonce: gzipOnce,\n};\n\n/**\n * Gzips a byte stream. `Z_SYNC_FLUSH` makes each written chunk readable at\n * once. It reads the next source chunk only when the consumer pulls, so a slow\n * client holds back the source. When the source ends by the time zlib\n * finishes a chunk, that chunk and the gzip trailer go out as one.\n *\n * A body that ends with its first chunk, up to 64 KiB, takes a pooled raw\n * deflate stream. Why: a new zlib stream costs more main-thread time than\n * zlib takes for a small page.\n *\n * @example\n * new Response(gzipStream(response.body), response);\n */\nexport function gzipStream(source: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {\n\treturn zlibStream(source, GZIP);\n}\n\nconst BROTLI: Codec = {\n\tcreate: () =>\n\t\tcreateBrotliCompress({ flush: constants.BROTLI_OPERATION_FLUSH, params: BROTLI_PARAMS }),\n\tempty: brotliCompressSync(new Uint8Array(), { params: BROTLI_PARAMS }),\n\tonce: brotliOnce,\n};\n\n/**\n * Compresses a byte stream with brotli, quality 4. `BROTLI_OPERATION_FLUSH`\n * makes each written chunk readable at once. It reads and ends as\n * {@link gzipStream} does, and a body that ends with its first chunk, up to\n * 64 KiB, also takes a pooled encoder.\n *\n * @example\n * new Response(brotliStream(response.body), response);\n */\nexport function brotliStream(source: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {\n\treturn zlibStream(source, BROTLI);\n}\n"],"mappings":";;;;;;;;AAeA,IAAM,WAAN,cAAuB,eAA2B;;CAEjD,AAAO,OAAO;AACf;;;;;;;;;AAUA,SAAgB,aAAa,QAAyD;CACrF,OAAO,kBAAkB,WAAW,OAAO,OAAO;AACnD;;;;;AAMA,MAAM,SAAS,OAAO,KAAK;CAAC;CAAI;CAAK;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;AAAC,CAAC;;AAG5D,MAAM,eAAe,OAAO,OAAO,CAAC,QAAQ,OAAO,KAAK;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;AAAC,CAAC,CAAC,CAAC;;;;;;AAOxF,MAAM,mBAAmB;;AAGzB,MAAM,WAAW;AAEjB,SAAS,SAAe,CAAC;AA2BzB,SAAS,UAAU,MAAoB;CACtC,MAAM,SAAiB;EAAE,QAAQ,KAAK,OAAO;EAAG,QAAQ;EAAQ,MAAM;EAAQ,MAAM;CAAE;CACtF,OAAO,OAAO,GAAG,SAAS,UAAkB;EAC3C,OAAO,OAAO,KAAK;CACpB,CAAC;CAED,OAAO,OAAO,GAAG,UAAU,UAAU;EACpC,OAAO,KAAK,KAAK;CAClB,CAAC;CACD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