@ngrok/app-server 0.1.1 → 0.2.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 +75 -20
- package/dist/build-manifest-8NfD1wnO.js +45 -0
- package/dist/build-manifest-8NfD1wnO.js.map +1 -0
- package/dist/{bun-DCGnDEPn.js → bun-BCz6K_Xv.js} +12 -8
- package/dist/bun-BCz6K_Xv.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/cli.js.map +1 -1
- package/dist/{deno-BnMfk2n1.js → deno-DNRgzHrk.js} +4 -4
- package/dist/deno-DNRgzHrk.js.map +1 -0
- package/dist/{entry-ChjmFwX5.js → entry-BkdUub2S.js} +179 -296
- package/dist/entry-BkdUub2S.js.map +1 -0
- package/dist/index-oSE-tYRW.d.ts +88 -0
- package/dist/index.d.ts +212 -27
- package/dist/index.js +26 -15
- package/dist/index.js.map +1 -1
- package/dist/{listen-options-DHWmSWGi.js → listen-options-7TaXjyrk.js} +2 -2
- package/dist/listen-options-7TaXjyrk.js.map +1 -0
- package/dist/load-entry-C03qqmhr.js +33 -0
- package/dist/load-entry-C03qqmhr.js.map +1 -0
- package/dist/log-CsjaKM8U.js +59 -0
- package/dist/log-CsjaKM8U.js.map +1 -0
- package/dist/{node-79my3Uix.js → node-CG7qXuWZ.js} +4 -4
- package/dist/node-CG7qXuWZ.js.map +1 -0
- package/dist/node-YWPGmzAk.js +215 -0
- package/dist/node-YWPGmzAk.js.map +1 -0
- package/dist/node-ZMowKZDB.js +3 -0
- package/dist/node-vite.d.ts +10 -0
- package/dist/node-vite.js +18 -0
- package/dist/node-vite.js.map +1 -0
- package/dist/node.d.ts +67 -0
- package/dist/node.js +4 -0
- package/dist/react-router-vite.d.ts +9 -0
- package/dist/react-router-vite.js +21 -0
- package/dist/react-router-vite.js.map +1 -0
- package/dist/react-router.d.ts +11 -24
- package/dist/react-router.js +15 -25
- package/dist/react-router.js.map +1 -1
- package/dist/serve-Cleo8RMO.js +29 -0
- package/dist/serve-Cleo8RMO.js.map +1 -0
- package/dist/{start-BVMb8Pyt.js → start-CINALHxy.js} +92 -72
- package/dist/start-CINALHxy.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +11 -0
- package/dist/tanstack-start-vite.js +24 -0
- package/dist/tanstack-start-vite.js.map +1 -0
- package/dist/tanstack-start.d.ts +17 -0
- package/dist/tanstack-start.js +50 -0
- package/dist/tanstack-start.js.map +1 -0
- package/dist/{tcp-Dau_IONd.js → tcp-C-9AmFuM.js} +5 -5
- package/dist/tcp-C-9AmFuM.js.map +1 -0
- package/dist/types-BfCkS7kQ.d.ts +203 -0
- package/dist/vite-mYZ2Y69u.js +144 -0
- package/dist/vite-mYZ2Y69u.js.map +1 -0
- package/dist/vite.d.ts +2 -27
- package/dist/vite.js +2 -2
- package/package.json +28 -2
- package/dist/bun-DCGnDEPn.js.map +0 -1
- package/dist/captured-headers-ewL_t3MQ.js +0 -48
- package/dist/captured-headers-ewL_t3MQ.js.map +0 -1
- package/dist/deno-BnMfk2n1.js.map +0 -1
- package/dist/entry-CIpwaayZ.d.ts +0 -293
- package/dist/entry-ChjmFwX5.js.map +0 -1
- package/dist/listen-options-DHWmSWGi.js.map +0 -1
- package/dist/node-2wWBMFeO.js +0 -3
- package/dist/node-79my3Uix.js.map +0 -1
- package/dist/serve-ByeedcRB.js +0 -16
- package/dist/serve-ByeedcRB.js.map +0 -1
- package/dist/start-BVMb8Pyt.js.map +0 -1
- package/dist/tcp-Dau_IONd.js.map +0 -1
- package/dist/vite-CrNqpoeK.js +0 -102
- package/dist/vite-CrNqpoeK.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-BkdUub2S.js","names":["requestId","honoRequestId","requestId"],"sources":["../src/core/plugins/access-log.ts","../src/core/plugins/request-id.ts","../src/core/static-files.ts","../src/core/plugins/static.ts","../src/core/plugins/streaming-compress.ts","../src/core/request-context.ts","../src/core/shutdown.ts","../src/core/create-server.ts","../src/core/entry.ts"],"sourcesContent":["import type { Context } from \"hono\";\nimport type { AppServerEnv, Plugin } from \"../types.js\";\n\n/** Options for {@link accessLog}. */\nexport type AccessLogOptions = {\n\t/**\n\t * Replace each query value with `REDACTED`, so a single-use code in a URL\n\t * never reaches a log.\n\t * @default true\n\t */\n\tredactQuery?: boolean;\n};\n\n/**\n * A URL's path and query, with each query value replaced when `redact` is set.\n *\n * @example\n * loggedUrl(new URL(\"https://example.com/verify?code=123\"), { redact: true }); // => \"/verify?code=REDACTED\"\n */\nexport function loggedUrl(url: URL, { redact }: { redact: boolean }): string {\n\tif (!redact || url.search === \"\") {\n\t\treturn `${url.pathname}${url.search}`;\n\t}\n\tconst query = [...url.searchParams.keys()]\n\t\t.map((key) => `${encodeURIComponent(key)}=REDACTED`)\n\t\t.join(\"&\");\n\treturn `${url.pathname}?${query}`;\n}\n\n/** A `Referer` with its query redacted like {@link loggedUrl}. A value that is not a URL is dropped. */\nfunction loggedReferer(referer: string | undefined, { redact }: { redact: boolean }) {\n\tif (referer == null || !redact) {\n\t\treturn referer;\n\t}\n\tconst url = URL.parse(referer);\n\treturn url == null ? undefined : `${url.origin}${loggedUrl(url, { redact })}`;\n}\n\n/**\n * One log line per request, static hits included, with Datadog standard\n * attribute names. The line goes out when the body ends or the client\n * disconnects, so a streamed response logs its full duration and size.\n *\n * @example\n * createServer({ plugins: [requestId(), accessLog({ redactQuery: false })] });\n * // {\"level\":\"info\",\"message\":\"request\",\"http.status_code\":200,\"network.bytes_written\":5120,\"duration\":1830000,...}\n */\nexport function accessLog({ redactQuery = true }: AccessLogOptions = {}): Plugin {\n\treturn {\n\t\tname: \"access-log\",\n\t\tmiddleware: async (context, next) => {\n\t\t\tconst started = performance.now();\n\t\t\tawait next();\n\t\t\tconst write = ({ bytes, aborted }: { bytes: number; aborted: boolean }) => {\n\t\t\t\tcontext.var.logger.info(\"request\", lineAttributes(context, { bytes, aborted, started }));\n\t\t\t};\n\t\t\tconst response = context.res;\n\t\t\t// Why HEAD: Hono drops the body of a HEAD response, so no one reads it to its end.\n\t\t\tif (context.req.method === \"HEAD\") {\n\t\t\t\twrite({ bytes: 0, aborted: false });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Why `Content-Length`: a stage that answers through Node's response, such as Vite in\n\t\t\t// development, gives a response with no body and the length it sent.\n\t\t\tif (response.body == null) {\n\t\t\t\twrite({ bytes: Number(response.headers.get(\"Content-Length\") ?? 0), aborted: false });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst reader = response.body.getReader();\n\t\t\tlet bytes = 0;\n\t\t\tconst counted = new ReadableStream<Uint8Array>({\n\t\t\t\tasync pull(controller) {\n\t\t\t\t\tlet result: ReadableStreamReadResult<Uint8Array>;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tresult = await reader.read();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Why here: `cancel` does not run for a stream that failed.\n\t\t\t\t\t\twrite({ bytes, aborted: true });\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tconst { done, value } = result;\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\twrite({ bytes, aborted: false });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tbytes += value.byteLength;\n\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t},\n\t\t\t\tasync cancel(reason) {\n\t\t\t\t\twrite({ bytes, aborted: true });\n\t\t\t\t\tawait reader.cancel(reason);\n\t\t\t\t},\n\t\t\t});\n\t\t\tcontext.res = new Response(counted, response);\n\t\t},\n\t};\n\n\tfunction lineAttributes(\n\t\tcontext: Context<AppServerEnv>,\n\t\t{ bytes, aborted, started }: { bytes: number; aborted: boolean; started: number },\n\t): Record<string, unknown> {\n\t\treturn {\n\t\t\t\"http.url\": loggedUrl(new URL(context.req.url), { redact: redactQuery }),\n\t\t\t\"http.status_code\": context.res.status,\n\t\t\t\"http.useragent\": context.req.header(\"User-Agent\"),\n\t\t\t\"http.referer\": loggedReferer(context.req.header(\"Referer\"), { redact: redactQuery }),\n\t\t\t\"network.client.ip\": context.env.remoteAddress,\n\t\t\t\"network.bytes_written\": bytes,\n\t\t\t// Why nanoseconds: Datadog's standard `duration` attribute is in nanoseconds.\n\t\t\tduration: Math.round((performance.now() - started) * 1_000_000),\n\t\t\t...(aborted ? { \"http.client_aborted\": true } : {}),\n\t\t};\n\t}\n}\n","import { requestId as honoRequestId } from \"hono/request-id\";\nimport type { Plugin } from \"../types.js\";\n\n/** Options for {@link requestId}. */\nexport type RequestIdOptions = {\n\t/** @default \"X-Request-Id\" */\n\theaderName?: string;\n};\n\n/**\n * Gives each request an ID: a valid incoming header (up to 255 word\n * characters, `-`, and `=`), else a new UUID. The ID goes on the response, on\n * every log line, and into the framework's context.\n *\n * @example\n * const app = createServer({ plugins: [requestId()] });\n * const response = await app.request(\"/\", { headers: { \"X-Request-Id\": \"abc-123\" } });\n * response.headers.get(\"X-Request-Id\"); // => \"abc-123\"\n */\nexport function requestId({ headerName = \"X-Request-Id\" }: RequestIdOptions = {}): Plugin {\n\tconst assign = honoRequestId({ headerName });\n\treturn {\n\t\tname: \"request-id\",\n\t\tmiddleware: async (context, next) => {\n\t\t\tawait assign(context, next);\n\t\t\t// Why set it again: a `Response` that the framework returns replaces the headers set before `next`.\n\t\t\t// `context.header` also copies a response whose headers are immutable.\n\t\t\tconst id = context.get(\"requestId\");\n\t\t\tif (id != null) {\n\t\t\t\tcontext.header(headerName, id);\n\t\t\t}\n\t\t},\n\t};\n}\n","import type { Context } from \"hono\";\nimport { getMimeType } from \"hono/utils/mime\";\nimport type { AppServerEnv, StaticFiles } from \"./types.js\";\n\n/** A file under the client build that answers a request. */\nexport type StaticFile = {\n\t/** The URL path of the file, such as `/components/button/index.html`. */\n\tpath: string;\n\tsize: number;\n\tmtimeMs: number;\n};\n\n/** The content types that `mime` lacks and that no framework owns. */\nconst CORE_CONTENT_TYPES: Readonly<Record<string, string>> = {\n\t\".md\": \"text/markdown; charset=utf-8\",\n};\n\n/**\n * Whether a URL path names a dotfile or goes through a dot directory.\n * `/.well-known/` stays reachable.\n */\nfunction hasDotSegment(path: string): boolean {\n\treturn path\n\t\t.split(\"/\")\n\t\t.some(\n\t\t\t(segment, index) => segment.startsWith(\".\") && !(index === 1 && segment === \".well-known\"),\n\t\t);\n}\n\n/**\n * Finds the file in `files` that answers a decoded URL path, such as Hono's\n * `context.req.path`. A directory answers with its `index.html` and no\n * redirect, so a prerendered page keeps its URL. Dotfiles and paths that\n * leave the client build find nothing.\n *\n * Each file has one URL, because the headers for a file are keyed by that\n * URL. So `/a//b`, `/a/index.html`, and `/a%2Fb` find nothing. Hono decodes\n * the path but keeps an encoded `/` as `%2F`, so this function does not\n * decode it again.\n *\n * @example\n * await findStaticFile(files, \"/components/button\");\n * // => { path: \"/components/button/index.html\", size: 5120, mtimeMs: 1761652800000 }\n */\nexport async function findStaticFile(\n\tfiles: StaticFiles,\n\tpath: string,\n): Promise<StaticFile | undefined> {\n\tif (\n\t\t!path.startsWith(\"/\") ||\n\t\tpath.includes(\"\\0\") ||\n\t\tpath.includes(\"\\\\\") ||\n\t\tpath.split(\"/\").includes(\"..\") ||\n\t\tpath.includes(\"//\") ||\n\t\tpath.endsWith(\"/index.html\") ||\n\t\thasDotSegment(path)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst info = await files.stat(path);\n\tif (info?.kind === \"file\") {\n\t\treturn { path, size: info.size, mtimeMs: info.mtimeMs };\n\t}\n\tif (info?.kind === \"directory\") {\n\t\tconst index = `${path.replace(/\\/$/u, \"\")}/index.html`;\n\t\tconst indexInfo = await files.stat(index);\n\t\tif (indexInfo?.kind === \"file\") {\n\t\t\treturn { path: index, size: indexInfo.size, mtimeMs: indexInfo.mtimeMs };\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** The content type of a file, by its extension. `contentTypes` win over `mime`. */\nfunction contentType(path: string, contentTypes: Readonly<Record<string, string>>): string {\n\tconst extension = /\\.[^./]+$/u.exec(path)?.[0] ?? \"\";\n\treturn (\n\t\tcontentTypes[extension] ??\n\t\tCORE_CONTENT_TYPES[extension] ??\n\t\tgetMimeType(path) ??\n\t\t\"application/octet-stream\"\n\t);\n}\n\n/** An ETag without its weak prefix, for the weak comparison that `If-None-Match` uses. */\nfunction opaqueTag(etag: string): string {\n\treturn etag.trim().replace(/^W\\//u, \"\");\n}\n\n/** Whether an `If-None-Match` header lists an ETag. */\nfunction matchesEtag(ifNoneMatch: string | undefined, etag: string): boolean {\n\treturn (\n\t\tifNoneMatch?.split(\",\").some((candidate) => {\n\t\t\tconst trimmed = candidate.trim();\n\t\t\treturn trimmed === \"*\" || opaqueTag(trimmed) === opaqueTag(etag);\n\t\t}) ?? false\n\t);\n}\n\n/** A weak ETag from a file's size, its modification time, and the request's `etagParts`. */\nasync function fileEtag(file: StaticFile, parts: readonly string[]): Promise<string> {\n\tconst base = `${file.size.toString(16)}-${Math.trunc(file.mtimeMs).toString(16)}`;\n\tif (parts.length === 0) {\n\t\treturn `W/\"${base}\"`;\n\t}\n\t// Why Web Crypto: each host has it, and the core imports no Node module.\n\tconst digest = await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(parts.join(\"\\0\")));\n\tconst hash = btoa(String.fromCodePoint(...new Uint8Array(digest)))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.slice(0, 16);\n\treturn `W/\"${base}-${hash}\"`;\n}\n\n/** What {@link staticResponse} needs besides the request. */\nexport type StaticResponseOptions = {\n\tfiles: StaticFiles;\n\tfile: StaticFile;\n\t/** Headers that replace the defaults, so a captured `Content-Type` wins over the one from the file name. */\n\theaders: Readonly<Record<string, string>>;\n\tcontentTypes: Readonly<Record<string, string>>;\n};\n\n/**\n * The response for a static file, with a weak ETag from its size,\n * modification time, and the request's `etagParts`. A matching\n * `If-None-Match` gets a 304, and `HEAD` gets the headers only.\n */\nexport async function staticResponse(\n\tcontext: Context<AppServerEnv>,\n\t{ files, file, headers, contentTypes }: StaticResponseOptions,\n): Promise<Response> {\n\tconst etag = await fileEtag(file, context.get(\"etagParts\") ?? []);\n\tconst responseHeaders = new Headers({\n\t\t\"Content-Type\": contentType(file.path, contentTypes),\n\t\tETag: etag,\n\t});\n\tfor (const [name, value] of Object.entries(headers)) {\n\t\tresponseHeaders.set(name, value);\n\t}\n\t// Why the final header: `headers` can replace the ETag.\n\tif (matchesEtag(context.req.header(\"If-None-Match\"), responseHeaders.get(\"ETag\") ?? etag)) {\n\t\tresponseHeaders.delete(\"Content-Type\");\n\t\treturn new Response(null, { status: 304, headers: responseHeaders });\n\t}\n\tresponseHeaders.set(\"Content-Length\", String(file.size));\n\tif (context.req.method === \"HEAD\") {\n\t\treturn new Response(null, { headers: responseHeaders });\n\t}\n\treturn new Response(await files.open(file.path), { headers: responseHeaders });\n}\n","import type { Context, MiddlewareHandler } from \"hono\";\nimport { manifestKey } from \"../build-manifest.js\";\nimport { findStaticFile, staticResponse } from \"../static-files.js\";\nimport type { AppServerEnv, Plugin } from \"../types.js\";\n\nconst IMMUTABLE = \"public, max-age=31536000, immutable\";\n\n/**\n * Serves the hashed files under `/assets/` with a one-year immutable cache.\n * A missing asset gets a plain 404, not a rendered page. In development,\n * the dev server serves the source modules, the HMR client, and the CSS here\n * instead.\n *\n * @example\n * createServer({ plugins: [requestId(), accessLog(), streamingCompress(), assets(), prerendered()] });\n */\nexport function assets(): Plugin {\n\tlet stage: MiddlewareHandler<AppServerEnv> | undefined;\n\treturn {\n\t\tname: \"assets\",\n\t\tsetup: (info) => {\n\t\t\tif (info.mode === \"development\") {\n\t\t\t\tstage = info.devServer;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { files, contentTypes } = info;\n\t\t\tstage = async (context, next) => {\n\t\t\t\tconst { method, path } = context.req;\n\t\t\t\tif (!path.startsWith(\"/assets/\") || (method !== \"GET\" && method !== \"HEAD\")) {\n\t\t\t\t\treturn next();\n\t\t\t\t}\n\t\t\t\tconst file = await findStaticFile(files, path);\n\t\t\t\tif (file == null) {\n\t\t\t\t\treturn context.text(\"Not Found\", 404);\n\t\t\t\t}\n\t\t\t\treturn staticResponse(context, {\n\t\t\t\t\tfiles,\n\t\t\t\t\tfile,\n\t\t\t\t\theaders: { \"Cache-Control\": IMMUTABLE },\n\t\t\t\t\tcontentTypes,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t\tmiddleware: async (context, next) => (stage == null ? next() : stage(context, next)),\n\t};\n}\n\n/** Options for {@link prerendered}. */\nexport type PrerenderedOptions = {\n\t/**\n\t * Extra headers for a served file, by its URL path. They replace the\n\t * headers captured at build time.\n\t */\n\theaders?: (\n\t\tpath: string,\n\t\tcontext: Context<AppServerEnv>,\n\t) => Readonly<Record<string, string>> | undefined;\n\t/**\n\t * Maps a request path to the URL path of the file to serve, for content\n\t * negotiation. Return the path unchanged to serve the usual file. The\n\t * returned path follows the rules of a request path: one URL for each\n\t * file, no dotfiles, and nothing outside the client build. When the\n\t * answer depends on a request header, add a `Vary` for it in a plugin.\n\t */\n\trewrite?: (path: string, context: Context<AppServerEnv>) => string;\n};\n\n/**\n * Serves the client build: prerendered pages at their own URL with a 200 and\n * no trailing-slash redirect, plus every other file in it. Each response gets\n * the headers its loader sent at build time (the `appServer` Vite plugin\n * captures them), an ETag, and a 304 for a matching `If-None-Match`. A path\n * with no file goes on to the framework. Off in development.\n *\n * At startup, it warns about each prerendered path that has no file.\n *\n * @example\n * prerendered({\n * \theaders: (path) => (path.startsWith(\"/api/\") ? { \"Access-Control-Allow-Origin\": \"*\" } : undefined),\n * });\n */\nexport function prerendered(options: PrerenderedOptions = {}): Plugin {\n\tlet stage: MiddlewareHandler<AppServerEnv> | undefined;\n\treturn {\n\t\tname: \"prerendered\",\n\t\tsetup: async (info) => {\n\t\t\tif (info.mode === \"development\") {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { files, contentTypes, capturedHeaders } = info;\n\t\t\tconst missing: string[] = [];\n\t\t\tfor (const path of info.prerenderedPaths) {\n\t\t\t\tif ((await findStaticFile(files, path)) == null) {\n\t\t\t\t\tmissing.push(path);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (missing.length > 0) {\n\t\t\t\t// Why a warning: a path with no file falls through to the framework, which still answers.\n\t\t\t\tinfo.logger.log(\"warn\", \"prerendered paths with no file\", {\n\t\t\t\t\t\"app_server.missing_paths\": missing,\n\t\t\t\t});\n\t\t\t}\n\t\t\tstage = async (context, next) => {\n\t\t\t\tconst { method } = context.req;\n\t\t\t\tif (method !== \"GET\" && method !== \"HEAD\") {\n\t\t\t\t\treturn next();\n\t\t\t\t}\n\t\t\t\tconst path = options.rewrite?.(context.req.path, context) ?? context.req.path;\n\t\t\t\tconst file = await findStaticFile(files, path);\n\t\t\t\tif (file == null) {\n\t\t\t\t\treturn next();\n\t\t\t\t}\n\t\t\t\treturn staticResponse(context, {\n\t\t\t\t\tfiles,\n\t\t\t\t\tfile,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t...capturedHeaders.get(manifestKey(path)),\n\t\t\t\t\t\t...options.headers?.(path, context),\n\t\t\t\t\t},\n\t\t\t\t\tcontentTypes,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t\tmiddleware: async (context, next) => (stage == null ? next() : stage(context, next)),\n\t};\n}\n","import { accepts } from \"hono/accepts\";\nimport type { Plugin, SetupInfo } from \"../types.js\";\n\nconst COMPRESSIBLE =\n\t/^(?:text\\/|application\\/(?:json|javascript|xml|schema\\+json|manifest\\+json|x-ndjson|connect\\+json)|image\\/svg\\+xml)/u;\n\n/**\n * Gzips text responses and flushes after each chunk, so a streamed page shell\n * or a server-sent event reaches the client at once. `hono/compress` holds a\n * stream until it ends. Skips a response that is already encoded, a partial\n * response, and one marked `no-transform`. It sets `Vary: Accept-Encoding` on\n * each response. The host gives the gzip stream. On a host with none, the\n * plugin does nothing.\n *\n * @example\n * createServer({ plugins: [requestId(), accessLog(), streamingCompress()] });\n */\nexport function streamingCompress(): Plugin {\n\tlet gzip: SetupInfo[\"gzip\"];\n\treturn {\n\t\tname: \"streaming-compress\",\n\t\tsetup: (info) => {\n\t\t\t({ gzip } = info);\n\t\t},\n\t\tmiddleware: async (context, next) => {\n\t\t\tawait next();\n\t\t\tif (gzip == null) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Why `context.header`: it copies a response whose headers are immutable, such as one from `fetch`.\n\t\t\tcontext.header(\"Vary\", \"Accept-Encoding\", { append: true });\n\t\t\tconst response = context.res;\n\t\t\tif (\n\t\t\t\tresponse.body == null ||\n\t\t\t\tcontext.req.method === \"HEAD\" ||\n\t\t\t\taccepts(context, { header: \"Accept-Encoding\", supports: [\"gzip\"], default: \"identity\" }) !==\n\t\t\t\t\t\"gzip\" ||\n\t\t\t\tresponse.headers.has(\"Content-Encoding\") ||\n\t\t\t\t// Why: gzip changes the bytes, so a `Content-Range` would no longer match them.\n\t\t\t\tresponse.headers.has(\"Content-Range\") ||\n\t\t\t\t/\\bno-transform\\b/u.test(response.headers.get(\"Cache-Control\") ?? \"\") ||\n\t\t\t\t!COMPRESSIBLE.test(response.headers.get(\"Content-Type\") ?? \"\")\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcontext.res = new Response(gzip(response.body), response);\n\t\t\t// Why after the assignment: Hono copies the old response's headers onto the new one.\n\t\t\tcontext.res.headers.set(\"Content-Encoding\", \"gzip\");\n\t\t\tcontext.res.headers.delete(\"Content-Length\");\n\t\t},\n\t};\n}\n","import type { Context } from \"hono\";\nimport type { AppServerEnv, RequestContext, RequestStore } from \"./types.js\";\n\n/**\n * Each store that a request ran in. Why a set: two entries in one process can\n * have two hosts, and each request uses the store of its own app.\n */\nconst stores = new Set<RequestStore>();\n\n/** Runs `work` in `store` with `context` as the request that {@link requestContext} reads. */\nexport async function withRequestContext(\n\tstore: RequestStore | undefined,\n\tcontext: Context<AppServerEnv>,\n\twork: () => Promise<void>,\n): Promise<void> {\n\tif (store == null) {\n\t\treturn work();\n\t}\n\tstores.add(store);\n\treturn store.run(context, work);\n}\n\n/**\n * The request ID and logger of the request that runs. It gives `undefined`\n * outside a server request, such as in a prerender pass, or on a host with no\n * request storage.\n *\n * @example\n * export async function loader() {\n * \trequestContext()?.logger.info(\"loading the dashboard\");\n * }\n */\nexport function requestContext(): RequestContext | undefined {\n\tfor (const store of stores) {\n\t\tconst context = store.get();\n\t\tif (context != null) {\n\t\t\treturn { requestId: context.get(\"requestId\"), logger: context.var.logger };\n\t\t}\n\t}\n\treturn undefined;\n}\n","let controller = new AbortController();\n\n/**\n * A signal that aborts when the server starts to shut down. Read it for each\n * request: each start of a server makes a new one. A handler that\n * holds a response open, such as an event stream, stops on it so that the\n * drain does not wait for the deadline.\n *\n * @example\n * const timer = setInterval(sendUpdate, 1_000);\n * shutdownSignal().addEventListener(\"abort\", () => clearInterval(timer), { once: true });\n */\nexport function shutdownSignal(): AbortSignal {\n\treturn controller.signal;\n}\n\n/** Replaces {@link shutdownSignal} with a new one that has not aborted. */\nexport function renewShutdownSignal(): void {\n\tcontroller = new AbortController();\n}\n\n/** Aborts {@link shutdownSignal}. */\nexport function abortShutdownSignal(): void {\n\tcontroller.abort();\n}\n","import { Hono } from \"hono\";\nimport { errorAttributes, jsonSink, requestLogger } from \"./log.js\";\nimport { accessLog } from \"./plugins/access-log.js\";\nimport type { AccessLogOptions } from \"./plugins/access-log.js\";\nimport { requestId } from \"./plugins/request-id.js\";\nimport type { RequestIdOptions } from \"./plugins/request-id.js\";\nimport { assets, prerendered } from \"./plugins/static.js\";\nimport type { PrerenderedOptions } from \"./plugins/static.js\";\nimport { streamingCompress } from \"./plugins/streaming-compress.js\";\nimport { withRequestContext } from \"./request-context.js\";\nimport { abortShutdownSignal, renewShutdownSignal } from \"./shutdown.js\";\nimport type {\n\tAppServerEnv,\n\tFetchHandler,\n\tFrameworkRuntime,\n\tListener,\n\tLogSink,\n\tPlugin,\n\tRequestStore,\n\tSetupInfo,\n} from \"./types.js\";\n\n// Why a WeakMap: only this copy of the package reads an app's internals, through `createEntry`.\nconst appInternals = new WeakMap<AppServer, ServerInternals>();\n\n/** A Hono app from {@link createServer}. Add routes to it before you export it. */\nexport type AppServer = Hono<AppServerEnv>;\n\n/** A server that listens. */\nexport type RunningServer = {\n\t/** The URL of each listener. */\n\turls: readonly string[];\n\t/**\n\t * Aborts `shutdownSignal()`, then runs each plugin's `onShutdown` while the\n\t * listeners stop and drain open requests. Both stop at the deadline.\n\t */\n\tshutdown: () => Promise<void>;\n};\n\n/** What `createEntry` calls on an app. */\nexport type ServerInternals = {\n\tlogger: LogSink;\n\t/** Runs each plugin's `setup` once and adds the framework handler after the app's routes. */\n\tprepare: (info: SetupInfo) => Promise<void>;\n\t/**\n\t * Starts the app's listeners, else `defaultListeners`, the host's. Call\n\t * `prepare` first.\n\t */\n\tlisten: (\n\t\tframework: FrameworkRuntime,\n\t\tdefaultListeners: readonly Listener[],\n\t) => Promise<RunningServer>;\n\t/** Runs each plugin's `onShutdown` once, and stops waiting for them at the shutdown deadline. */\n\tstopPlugins: () => Promise<void>;\n\t/** Sets the storage for `requestContext()` in this app's requests. `createEntry` sets the host's. */\n\tsetRequestStore: (store: RequestStore | undefined) => void;\n};\n\n/** Options for {@link defaultPlugins}. */\nexport type DefaultPluginsOptions = {\n\trequestId?: RequestIdOptions;\n\taccessLog?: AccessLogOptions;\n\tprerendered?: PrerenderedOptions;\n\t/**\n\t * Plugins that go after compression and before the static stages, so they\n\t * see every response, prerendered pages included. `runtimeEnv` and\n\t * `buildId` go here.\n\t */\n\tbeforeStatic?: readonly Plugin[];\n};\n\n/**\n * The default pipeline, in order: `requestId`, `accessLog`,\n * `streamingCompress`, the `beforeStatic` plugins, `assets`, and\n * `prerendered`. It is a plain array, so an app can filter it or splice into it.\n *\n * @example\n * createServer({ plugins: defaultPlugins({ accessLog: { redactQuery: false }, beforeStatic: [env] }) });\n */\nexport function defaultPlugins(options: DefaultPluginsOptions = {}): Plugin[] {\n\treturn [\n\t\trequestId(options.requestId),\n\t\taccessLog(options.accessLog),\n\t\tstreamingCompress(),\n\t\t...(options.beforeStatic ?? []),\n\t\tassets(),\n\t\tprerendered(options.prerendered),\n\t];\n}\n\n/** Options for {@link createServer}. */\nexport type CreateServerOptions = {\n\t/** @default defaultPlugins() */\n\tplugins?: readonly Plugin[];\n\t/** @default jsonSink() */\n\tlogger?: LogSink;\n\t/** @default the host's listeners, such as `[tcp()]` on the node host */\n\tlisteners?: readonly Listener[];\n\t/**\n\t * Read the request scheme from `X-Forwarded-Proto`. Set it only behind a\n\t * proxy that overwrites that header, else a client can spoof it.\n\t * @default false\n\t */\n\ttrustForwardedProto?: boolean;\n\t/**\n\t * How long open requests get to finish after a stop signal.\n\t * @default 10000\n\t */\n\tshutdownDeadlineMs?: number;\n};\n\n/** The request with the scheme from `X-Forwarded-Proto`, when that header holds one. */\nfunction withForwardedProto(request: Request): Request {\n\tconst proto = request.headers.get(\"X-Forwarded-Proto\");\n\tif (proto !== \"http\" && proto !== \"https\") {\n\t\treturn request;\n\t}\n\tconst url = new URL(request.url);\n\turl.protocol = `${proto}:`;\n\treturn new Request(url, request);\n}\n\n/**\n * Runs `step`, and rethrows a thrown value that is not an `Error` as one.\n * Hono sends only an `Error` to `onError`, and rethrows any other value.\n */\nasync function asError<Result>(step: () => Promise<Result>): Promise<Result> {\n\ttry {\n\t\treturn await step();\n\t} catch (error) {\n\t\tthrow error instanceof Error\n\t\t\t? error\n\t\t\t: new Error(`A non-Error value was thrown: ${String(error)}`, { cause: error });\n\t}\n}\n\n/** Whether `work` settles before `ms` pass. */\nasync function settlesWithin(work: Promise<void>, ms: number): Promise<boolean> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst settled = await Promise.race([\n\t\twork.then(() => true),\n\t\tnew Promise<boolean>((resolve) => {\n\t\t\ttimer = setTimeout(resolve, ms, false);\n\t\t}),\n\t]);\n\tclearTimeout(timer);\n\treturn settled;\n}\n\n/**\n * Builds an app server: a Hono app that runs the plugins in list order, then\n * the app's own routes, then the framework. It does not listen; the\n * `app-server` CLI starts it.\n *\n * @example\n * // server.ts\n * const app = createServer({ logger: slogSink, plugins: defaultPlugins({ beforeStatic: [env] }) });\n * app.get(\"/livez\", (c) => c.text(\"ok\"));\n * export default app;\n */\nexport function createServer({\n\tplugins = defaultPlugins(),\n\tlogger = jsonSink(),\n\tlisteners,\n\ttrustForwardedProto = false,\n\tshutdownDeadlineMs = 10_000,\n}: CreateServerOptions = {}): AppServer {\n\tconst app = new Hono<AppServerEnv>();\n\tlet requestStore: RequestStore | undefined;\n\tif (trustForwardedProto) {\n\t\t// Why wrap `fetch`: every plugin and route, not only the framework, must see the trusted scheme.\n\t\tconst dispatch = app.fetch;\n\t\tapp.fetch = async (request, ...rest) => dispatch(withForwardedProto(request), ...rest);\n\t}\n\tapp.use(async (context, next) => {\n\t\tcontext.set(\"logger\", requestLogger(logger, context));\n\t\tawait withRequestContext(requestStore, context, next);\n\t\t// Why cancel: Hono drops the body of a HEAD response without a cancel, so a stream would run on.\n\t\tif (context.req.method === \"HEAD\") {\n\t\t\tawait context.res.body?.cancel();\n\t\t}\n\t});\n\t// Why `asError` at each step: a value that is not an `Error` becomes one where it is thrown,\n\t// so `onError` answers at once and each earlier plugin still sees the 500 after its `next`.\n\tfor (const { middleware, etagPart } of plugins) {\n\t\tapp.use(async (context, next) => {\n\t\t\tconst part = etagPart?.();\n\t\t\tif (part != null) {\n\t\t\t\tcontext.set(\"etagParts\", [...(context.get(\"etagParts\") ?? []), part]);\n\t\t\t}\n\t\t\treturn asError(async () => (middleware == null ? next() : middleware(context, next)));\n\t\t});\n\t}\n\tapp.use(async (_, next) => asError(next));\n\tapp.onError((error, context) => {\n\t\t// Why no `instanceof`: the app's routes can throw an `HTTPException` from another copy of Hono.\n\t\tif (\"getResponse\" in error && typeof error.getResponse === \"function\") {\n\t\t\tconst response: unknown = error.getResponse();\n\t\t\tif (response instanceof Response) {\n\t\t\t\treturn response;\n\t\t\t}\n\t\t}\n\t\tcontext.var.logger.error(\"unhandled error\", errorAttributes(error));\n\t\treturn context.text(\"Internal Server Error\", 500);\n\t});\n\n\tlet prepared: Promise<void> | undefined;\n\tlet running: RunningServer | undefined;\n\tlet stoppingPlugins: Promise<void> | undefined;\n\tconst internals: ServerInternals = {\n\t\tlogger,\n\t\tsetRequestStore: (store) => {\n\t\t\trequestStore = store;\n\t\t},\n\t\tprepare: async (info) => {\n\t\t\tprepared ??= (async () => {\n\t\t\t\tfor (const plugin of plugins) {\n\t\t\t\t\tawait plugin.setup?.(info);\n\t\t\t\t}\n\t\t\t\tapp.all(\"*\", async (context) => context.env.framework.fetch(context.req.raw, context));\n\t\t\t})();\n\t\t\treturn prepared;\n\t\t},\n\t\tlisten: async (framework, defaultListeners) => {\n\t\t\tif (running != null) {\n\t\t\t\tthrow new Error(\"This app server is already listening.\");\n\t\t\t}\n\t\t\trenewShutdownSignal();\n\t\t\tlet deadlinePassed = false;\n\t\t\tconst fetch: FetchHandler = async (request, bindings) => {\n\t\t\t\tconst response = await app.fetch(request, { ...bindings, framework });\n\t\t\t\t// Why: after the drain deadline, the listener closed the connection, so no one reads this\n\t\t\t\t// body. A cancel stops its producer, which can otherwise keep the process alive.\n\t\t\t\tif (deadlinePassed) {\n\t\t\t\t\tawait response.body?.cancel();\n\t\t\t\t}\n\t\t\t\treturn response;\n\t\t\t};\n\t\t\tconst starts = await Promise.allSettled(\n\t\t\t\t(listeners ?? defaultListeners).map(async (listener) => listener.start(fetch)),\n\t\t\t);\n\t\t\tconst started = starts.flatMap((start) =>\n\t\t\t\tstart.status === \"fulfilled\" ? [start.value] : [],\n\t\t\t);\n\t\t\tconst failed = starts.find((start) => start.status === \"rejected\");\n\t\t\tif (failed != null) {\n\t\t\t\t// Why stop the others: the caller gets no handle to stop them.\n\t\t\t\tawait Promise.all(started.map(async (listener) => listener.stop({ deadlineMs: 0 })));\n\t\t\t\tthrow failed.reason;\n\t\t\t}\n\t\t\tconst urls = started.map((listener) => listener.url);\n\t\t\tlogger.log(\"info\", \"listening\", { \"app_server.urls\": urls });\n\t\t\tlet stopping: Promise<void> | undefined;\n\t\t\trunning = {\n\t\t\t\turls,\n\t\t\t\tshutdown: async () => {\n\t\t\t\t\tstopping ??= (async () => {\n\t\t\t\t\t\tlogger.log(\"info\", \"draining\", { \"app_server.deadline_ms\": shutdownDeadlineMs });\n\t\t\t\t\t\tabortShutdownSignal();\n\t\t\t\t\t\tconst deadline = setTimeout(() => {\n\t\t\t\t\t\t\tdeadlinePassed = true;\n\t\t\t\t\t\t}, shutdownDeadlineMs);\n\t\t\t\t\t\t// Why at the same time: a plugin that hangs must not keep the listeners open.\n\t\t\t\t\t\t// Why settle all: the process exits after shutdown, so one failed stop must not cut\n\t\t\t\t\t\t// the other stops short.\n\t\t\t\t\t\tconst results = await Promise.allSettled([\n\t\t\t\t\t\t\tinternals.stopPlugins(),\n\t\t\t\t\t\t\t...started.map(async (listener) => listener.stop({ deadlineMs: shutdownDeadlineMs })),\n\t\t\t\t\t\t]);\n\t\t\t\t\t\tclearTimeout(deadline);\n\t\t\t\t\t\tconst rejected = results.find((result) => result.status === \"rejected\");\n\t\t\t\t\t\tif (rejected != null) {\n\t\t\t\t\t\t\tthrow rejected.reason;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlogger.log(\"info\", \"stopped\", {});\n\t\t\t\t\t})();\n\t\t\t\t\treturn stopping;\n\t\t\t\t},\n\t\t\t};\n\t\t\treturn running;\n\t\t},\n\t\tstopPlugins: async () => {\n\t\t\tstoppingPlugins ??= (async () => {\n\t\t\t\tconst hooks = (async () => {\n\t\t\t\t\tconst results = await Promise.allSettled(\n\t\t\t\t\t\tplugins.map(async (plugin) => plugin.onShutdown?.()),\n\t\t\t\t\t);\n\t\t\t\t\tfor (const result of results) {\n\t\t\t\t\t\tif (result.status === \"rejected\") {\n\t\t\t\t\t\t\tlogger.log(\"error\", \"plugin shutdown failed\", errorAttributes(result.reason));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\tif (!(await settlesWithin(hooks, shutdownDeadlineMs))) {\n\t\t\t\t\tlogger.log(\"warn\", \"plugin shutdown passed the deadline\", {\n\t\t\t\t\t\t\"app_server.deadline_ms\": shutdownDeadlineMs,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})();\n\t\t\treturn stoppingPlugins;\n\t\t},\n\t};\n\tappInternals.set(app, internals);\n\treturn app;\n}\n\n/** The internals of an app from {@link createServer} of this copy of the package, else `undefined`. */\nexport function serverInternals(app: AppServer): ServerInternals | undefined {\n\treturn appInternals.get(app);\n}\n","import type { MiddlewareHandler } from \"hono\";\nimport { 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 type {\n\tAppServerEnv,\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/** 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/** 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 development: FrameworkRuntime | undefined;\n\treturn {\n\t\tprotocol: ENTRY_PROTOCOL,\n\t\tapp,\n\t\tstart: async () => {\n\t\t\tconst runtime = framework(\"production\");\n\t\t\tconst shared = await setupInfo(runtime);\n\t\t\tconst { prerendered, headers } = await readBuildManifest(shared.files);\n\t\t\tconst info: SetupInfo = {\n\t\t\t\t...shared,\n\t\t\t\tmode: \"production\",\n\t\t\t\tprerenderedPaths: runtime.prerenderedPaths ?? prerendered,\n\t\t\t\tcapturedHeaders: new Map(Object.entries(headers)),\n\t\t\t};\n\t\t\tawait internals.prepare(info);\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\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});\n\t\t\treturn app.fetch(request, { ...bindings, framework: development });\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":";;;;;;;;;;;;;;AAmBA,SAAgB,UAAU,KAAU,EAAE,UAAuC;CAC5E,IAAI,CAAC,UAAU,IAAI,WAAW,IAC7B,OAAO,GAAG,IAAI,WAAW,IAAI;CAE9B,MAAM,QAAQ,CAAC,GAAG,IAAI,aAAa,KAAK,CAAC,CAAC,CACxC,KAAK,QAAQ,GAAG,mBAAmB,GAAG,EAAE,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AAS,MAAM,UAAU,OAAO;GACtC,MAAM,EAAE,aAAa,YAAY,MAAM,kBAAkB,OAAO,KAAK;GACrE,MAAM,OAAkB;IACvB,GAAG;IACH,MAAM;IACN,kBAAkB,QAAQ,oBAAoB;IAC9C,iBAAiB,IAAI,IAAI,OAAO,QAAQ,OAAO,CAAC;GACjD;GACA,MAAM,UAAU,QAAQ,IAAI;GAC5B,MAAM,SAAS,MAAM,UAAU,OAAO,SAAS,KAAK,UAAU,CAAC;GAC/D,KAAK,WAAW,OAAO,YACtB,OAAO,SAAS,CAAC,CAAC,OAAO,UAAmB;IAC3C,UAAU,OAAO,IAAI,SAAS,mBAAmB,gBAAgB,KAAK,CAAC;IACvE,MAAM;GACP,CAAC,CACF;EACD;EACA,UAAU,OAAO,SAAS,UAAU,cAAc;GACjD,gBAAgB,UAAU,aAAa;GACvC,MAAM,UAAU,QAAQ;IACvB,GAAI,MAAM,UAAU,WAAW;IAC/B,MAAM;IACN;IACA,kBAAkB,YAAY,oBAAoB,CAAC;IACnD,iCAAiB,IAAI,IAAI;GAC1B,CAAC;GACD,OAAO,IAAI,MAAM,SAAS;IAAE,GAAG;IAAU,WAAW;GAAY,CAAC;EAClE;EACA,aAAa,UAAU;EACvB;CACD;AACD;;;;;;;AAQA,SAAgB,iBAAiB,OAAyC;CACzE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,cAAc,SACd,MAAM;AAER"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Plugin, PreviewServer, ResolvedConfig } from "vite";
|
|
2
|
+
/** The module ID of the server entry that {@link appServer} generates. */
|
|
3
|
+
declare const SERVER_ENTRY_ID = "virtual:@ngrok/app-server/entry";
|
|
4
|
+
/**
|
|
5
|
+
* The build side of a framework adapter. The Vite config imports it, such as
|
|
6
|
+
* `reactRouterAdapter()` from `@ngrok/app-server/react-router/vite`.
|
|
7
|
+
*/
|
|
8
|
+
type FrameworkBuild = {
|
|
9
|
+
/** A name for logs and errors. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The Vite ID of the framework's server module, such as `virtual:react-router/server-build`. */
|
|
12
|
+
serverModule: string;
|
|
13
|
+
/**
|
|
14
|
+
* The module whose `runtime` export makes the run side from the server
|
|
15
|
+
* module. It has the type `FrameworkRuntimeFactory`.
|
|
16
|
+
*/
|
|
17
|
+
runtimeModule: string;
|
|
18
|
+
/**
|
|
19
|
+
* The source of an object literal with more options for `runtime`, such as
|
|
20
|
+
* a build constant of the framework. The bundler replaces the constants in
|
|
21
|
+
* it, because the source is part of the server entry.
|
|
22
|
+
*/
|
|
23
|
+
runtimeOptions?: string;
|
|
24
|
+
/** Whether a preview server runs the framework's prerender pass. */
|
|
25
|
+
isPrerenderPass: (server: PreviewServer) => boolean;
|
|
26
|
+
/** Throws for a config that the adapter does not support, so the build fails, not the first request. */
|
|
27
|
+
validate?: (config: ResolvedConfig) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The build side of a host adapter. The Vite config imports it, such as
|
|
31
|
+
* `node()` from `@ngrok/app-server/node/vite`.
|
|
32
|
+
*/
|
|
33
|
+
type HostBuild = {
|
|
34
|
+
/** A name for logs and errors. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** The module whose `host` export is the run side, a `HostRuntime`. */
|
|
37
|
+
runtimeModule: string;
|
|
38
|
+
/** The file name of the server entry in the server build, such as `app-server.js`. */
|
|
39
|
+
entryFileName: string;
|
|
40
|
+
};
|
|
41
|
+
/** Options for {@link appServer}. */
|
|
42
|
+
type AppServerOptions = {
|
|
43
|
+
framework: FrameworkBuild;
|
|
44
|
+
host: HostBuild;
|
|
45
|
+
/**
|
|
46
|
+
* The module whose default export is the app from `createServer`, relative
|
|
47
|
+
* to the Vite root. When omitted, the server uses its default plugins.
|
|
48
|
+
*/
|
|
49
|
+
app?: string;
|
|
50
|
+
};
|
|
51
|
+
/** What {@link serverEntrySource} needs. */
|
|
52
|
+
type EntrySource = {
|
|
53
|
+
framework: Pick<FrameworkBuild, "serverModule" | "runtimeModule" | "runtimeOptions">;
|
|
54
|
+
host: Pick<HostBuild, "runtimeModule">;
|
|
55
|
+
/** The absolute path of the app module, else `undefined` for the default app. */
|
|
56
|
+
appModule: string | undefined;
|
|
57
|
+
/** The source of an expression that gives the client build: a path or a `file:` URL. */
|
|
58
|
+
clientDirectory: string;
|
|
59
|
+
};
|
|
60
|
+
/** The source of the server entry. */
|
|
61
|
+
declare function serverEntrySource({ framework, host, appModule, clientDirectory }: EntrySource): string;
|
|
62
|
+
/**
|
|
63
|
+
* The Vite plugin for `@ngrok/app-server`. Put it next to the framework's
|
|
64
|
+
* plugin.
|
|
65
|
+
*
|
|
66
|
+
* - It adds the server entry to the server build, such as
|
|
67
|
+
* `build/server/app-server.js` on the node host. The entry bundles the app
|
|
68
|
+
* (the default export of `app`) with the framework's server module, so the
|
|
69
|
+
* server gets the app's path aliases and its one copy of the framework.
|
|
70
|
+
* The framework's own entry does not change.
|
|
71
|
+
* - During the framework's prerender pass, it records each prerendered path
|
|
72
|
+
* and the headers of each prerendered file that is not an HTML document into
|
|
73
|
+
* `.app-server.json` in the client build. The `prerendered` plugin replays
|
|
74
|
+
* the headers. A document's headers depend on its request, so they are not
|
|
75
|
+
* recorded.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // vite.config.ts
|
|
79
|
+
* export default defineConfig({
|
|
80
|
+
* plugins: [
|
|
81
|
+
* reactRouter(),
|
|
82
|
+
* appServer({ framework: reactRouterAdapter(), host: node(), app: "./server.ts" }),
|
|
83
|
+
* ],
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
declare function appServer({ framework, host, app }: AppServerOptions): Plugin;
|
|
87
|
+
export { appServer as a, SERVER_ENTRY_ID as i, FrameworkBuild as n, serverEntrySource as o, HostBuild as r, AppServerOptions as t };
|
|
88
|
+
//# sourceMappingURL=index-oSE-tYRW.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,194 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context } from "hono";
|
|
1
|
+
import { _ as ServerBindings, a as FrameworkRuntimeFactory, b as StaticFiles, c as Listener, d as LogSink, f as Mode, g as RequestStore, h as RequestLogger, i as FrameworkRuntime, l as ListenerBindings, m as RequestContext, n as FetchHandler, o as HostRuntime, p as Plugin, r as FileInfo, s as Lifecycle, t as AppServerEnv, u as LogLevel, v as SetupInfo, y as StartedListener } from "./types-BfCkS7kQ.js";
|
|
2
|
+
import { Context, Hono, MiddlewareHandler } from "hono";
|
|
3
|
+
/** Options for {@link accessLog}. */
|
|
4
|
+
type AccessLogOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Replace each query value with `REDACTED`, so a single-use code in a URL
|
|
7
|
+
* never reaches a log.
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
redactQuery?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* One log line per request, static hits included, with Datadog standard
|
|
14
|
+
* attribute names. The line goes out when the body ends or the client
|
|
15
|
+
* disconnects, so a streamed response logs its full duration and size.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* createServer({ plugins: [requestId(), accessLog({ redactQuery: false })] });
|
|
19
|
+
* // {"level":"info","message":"request","http.status_code":200,"network.bytes_written":5120,"duration":1830000,...}
|
|
20
|
+
*/
|
|
21
|
+
export declare function accessLog({ redactQuery }?: AccessLogOptions): Plugin;
|
|
22
|
+
/** Options for {@link requestId}. */
|
|
23
|
+
type RequestIdOptions = {
|
|
24
|
+
/** @default "X-Request-Id" */
|
|
25
|
+
headerName?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Gives each request an ID: a valid incoming header (up to 255 word
|
|
29
|
+
* characters, `-`, and `=`), else a new UUID. The ID goes on the response, on
|
|
30
|
+
* every log line, and into the framework's context.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const app = createServer({ plugins: [requestId()] });
|
|
34
|
+
* const response = await app.request("/", { headers: { "X-Request-Id": "abc-123" } });
|
|
35
|
+
* response.headers.get("X-Request-Id"); // => "abc-123"
|
|
36
|
+
*/
|
|
37
|
+
export declare function requestId({ headerName }?: RequestIdOptions): Plugin;
|
|
38
|
+
/**
|
|
39
|
+
* Serves the hashed files under `/assets/` with a one-year immutable cache.
|
|
40
|
+
* A missing asset gets a plain 404, not a rendered page. In development,
|
|
41
|
+
* the dev server serves the source modules, the HMR client, and the CSS here
|
|
42
|
+
* instead.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* createServer({ plugins: [requestId(), accessLog(), streamingCompress(), assets(), prerendered()] });
|
|
46
|
+
*/
|
|
47
|
+
export declare function assets(): Plugin;
|
|
48
|
+
/** Options for {@link prerendered}. */
|
|
49
|
+
type PrerenderedOptions = {
|
|
50
|
+
/**
|
|
51
|
+
* Extra headers for a served file, by its URL path. They replace the
|
|
52
|
+
* headers captured at build time.
|
|
53
|
+
*/
|
|
54
|
+
headers?: (path: string, context: Context<AppServerEnv>) => Readonly<Record<string, string>> | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Maps a request path to the URL path of the file to serve, for content
|
|
57
|
+
* negotiation. Return the path unchanged to serve the usual file. The
|
|
58
|
+
* returned path follows the rules of a request path: one URL for each
|
|
59
|
+
* file, no dotfiles, and nothing outside the client build. When the
|
|
60
|
+
* answer depends on a request header, add a `Vary` for it in a plugin.
|
|
61
|
+
*/
|
|
62
|
+
rewrite?: (path: string, context: Context<AppServerEnv>) => string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Serves the client build: prerendered pages at their own URL with a 200 and
|
|
66
|
+
* no trailing-slash redirect, plus every other file in it. Each response gets
|
|
67
|
+
* the headers its loader sent at build time (the `appServer` Vite plugin
|
|
68
|
+
* captures them), an ETag, and a 304 for a matching `If-None-Match`. A path
|
|
69
|
+
* with no file goes on to the framework. Off in development.
|
|
70
|
+
*
|
|
71
|
+
* At startup, it warns about each prerendered path that has no file.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* prerendered({
|
|
75
|
+
* headers: (path) => (path.startsWith("/api/") ? { "Access-Control-Allow-Origin": "*" } : undefined),
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
export declare function prerendered(options?: PrerenderedOptions): Plugin;
|
|
79
|
+
/** A Hono app from {@link createServer}. Add routes to it before you export it. */
|
|
80
|
+
type AppServer = Hono<AppServerEnv>;
|
|
81
|
+
/** A server that listens. */
|
|
82
|
+
type RunningServer = {
|
|
83
|
+
/** The URL of each listener. */
|
|
84
|
+
urls: readonly string[];
|
|
85
|
+
/**
|
|
86
|
+
* Aborts `shutdownSignal()`, then runs each plugin's `onShutdown` while the
|
|
87
|
+
* listeners stop and drain open requests. Both stop at the deadline.
|
|
88
|
+
*/
|
|
89
|
+
shutdown: () => Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
/** Options for {@link defaultPlugins}. */
|
|
92
|
+
type DefaultPluginsOptions = {
|
|
93
|
+
requestId?: RequestIdOptions;
|
|
94
|
+
accessLog?: AccessLogOptions;
|
|
95
|
+
prerendered?: PrerenderedOptions;
|
|
96
|
+
/**
|
|
97
|
+
* Plugins that go after compression and before the static stages, so they
|
|
98
|
+
* see every response, prerendered pages included. `runtimeEnv` and
|
|
99
|
+
* `buildId` go here.
|
|
100
|
+
*/
|
|
101
|
+
beforeStatic?: readonly Plugin[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The default pipeline, in order: `requestId`, `accessLog`,
|
|
105
|
+
* `streamingCompress`, the `beforeStatic` plugins, `assets`, and
|
|
106
|
+
* `prerendered`. It is a plain array, so an app can filter it or splice into it.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* createServer({ plugins: defaultPlugins({ accessLog: { redactQuery: false }, beforeStatic: [env] }) });
|
|
110
|
+
*/
|
|
111
|
+
export declare function defaultPlugins(options?: DefaultPluginsOptions): Plugin[];
|
|
112
|
+
/** Options for {@link createServer}. */
|
|
113
|
+
type CreateServerOptions = {
|
|
114
|
+
/** @default defaultPlugins() */
|
|
115
|
+
plugins?: readonly Plugin[];
|
|
116
|
+
/** @default jsonSink() */
|
|
117
|
+
logger?: LogSink;
|
|
118
|
+
/** @default the host's listeners, such as `[tcp()]` on the node host */
|
|
119
|
+
listeners?: readonly Listener[];
|
|
120
|
+
/**
|
|
121
|
+
* Read the request scheme from `X-Forwarded-Proto`. Set it only behind a
|
|
122
|
+
* proxy that overwrites that header, else a client can spoof it.
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
trustForwardedProto?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* How long open requests get to finish after a stop signal.
|
|
128
|
+
* @default 10000
|
|
129
|
+
*/
|
|
130
|
+
shutdownDeadlineMs?: number;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Builds an app server: a Hono app that runs the plugins in list order, then
|
|
134
|
+
* the app's own routes, then the framework. It does not listen; the
|
|
135
|
+
* `app-server` CLI starts it.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* // server.ts
|
|
139
|
+
* const app = createServer({ logger: slogSink, plugins: defaultPlugins({ beforeStatic: [env] }) });
|
|
140
|
+
* app.get("/livez", (c) => c.text("ok"));
|
|
141
|
+
* export default app;
|
|
142
|
+
*/
|
|
143
|
+
export declare function createServer({ plugins, logger, listeners, trustForwardedProto, shutdownDeadlineMs }?: CreateServerOptions): AppServer;
|
|
144
|
+
/** The version of the contract between the CLI and the `appServer` export of a build. */
|
|
145
|
+
declare const ENTRY_PROTOCOL = 2;
|
|
146
|
+
/**
|
|
147
|
+
* What a server build exports as `appServer`. The CLI calls it, so the copy
|
|
148
|
+
* of this package in the build runs the server, and the CLI's copy runs
|
|
149
|
+
* nothing.
|
|
150
|
+
*/
|
|
151
|
+
type AppServerEntry = {
|
|
152
|
+
/** The CLI refuses an entry with another version. */
|
|
153
|
+
protocol: typeof ENTRY_PROTOCOL;
|
|
154
|
+
/** The app. Two entries with the same app share its plugins. */
|
|
155
|
+
app: AppServer;
|
|
156
|
+
/**
|
|
157
|
+
* Production: runs each plugin's `setup` and listens. When the host's
|
|
158
|
+
* lifecycle stops, such as on `SIGTERM`, it shuts down.
|
|
159
|
+
*/
|
|
160
|
+
start: () => Promise<void>;
|
|
161
|
+
/** Development: answers one request with the dev server inside the pipeline. */
|
|
162
|
+
fetchDev: (request: Request, bindings: ListenerBindings, devServer: MiddlewareHandler<AppServerEnv>) => Promise<Response>;
|
|
163
|
+
/** Runs each plugin's `onShutdown` once, up to the shutdown deadline. */
|
|
164
|
+
stopPlugins: () => Promise<void>;
|
|
165
|
+
/** Aborts `shutdownSignal()` of this copy of the package. */
|
|
166
|
+
abortShutdownSignal: () => void;
|
|
167
|
+
};
|
|
168
|
+
/** Options for {@link createEntry}. */
|
|
169
|
+
type CreateEntryOptions = {
|
|
170
|
+
/** The app from `createServer`. */
|
|
171
|
+
app: AppServer;
|
|
172
|
+
/** The run side of the host adapter, such as `host` from `@ngrok/app-server/node`. */
|
|
173
|
+
host: HostRuntime;
|
|
174
|
+
/** Makes the run side of the framework adapter for a mode. */
|
|
175
|
+
framework: (mode: Mode) => FrameworkRuntime;
|
|
176
|
+
/**
|
|
177
|
+
* The client build, as a file path or a `file:` URL. The entry that the
|
|
178
|
+
* Vite plugin generates sets it.
|
|
179
|
+
* @default the framework's `clientDirectory`
|
|
180
|
+
*/
|
|
181
|
+
clientDirectory?: string;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The `appServer` export of a server build: an app from `createServer`, the
|
|
185
|
+
* host, and the framework adapter for each mode. The `appServer` Vite plugin
|
|
186
|
+
* generates this export. Call this for a build without the plugin.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
|
|
190
|
+
*/
|
|
191
|
+
export declare function createEntry({ app, host, framework, clientDirectory }: CreateEntryOptions): AppServerEntry;
|
|
3
192
|
/** One server-sent event. */
|
|
4
193
|
type ServerSentEvent = {
|
|
5
194
|
data: string;
|
|
@@ -60,8 +249,9 @@ type BuildIdOptions = {
|
|
|
60
249
|
value: string;
|
|
61
250
|
};
|
|
62
251
|
/**
|
|
63
|
-
* Sets a build ID header on documents and
|
|
64
|
-
* a client can see that a deploy
|
|
252
|
+
* Sets a build ID header on documents and on the framework's data responses,
|
|
253
|
+
* such as React Router `.data` files, so a client can see that a deploy
|
|
254
|
+
* happened under it.
|
|
65
255
|
*
|
|
66
256
|
* @example
|
|
67
257
|
* buildId({ value: env.values.PUBLIC_APP_VERSION });
|
|
@@ -69,15 +259,15 @@ type BuildIdOptions = {
|
|
|
69
259
|
export declare function buildId({ header, value }: BuildIdOptions): Plugin;
|
|
70
260
|
type StandardIssue = {
|
|
71
261
|
readonly message: string;
|
|
72
|
-
readonly path?:
|
|
262
|
+
readonly path?: readonly (PropertyKey | {
|
|
73
263
|
readonly key: PropertyKey;
|
|
74
|
-
}
|
|
264
|
+
})[] | undefined;
|
|
75
265
|
};
|
|
76
266
|
type StandardResult<Output> = {
|
|
77
267
|
readonly value: Output;
|
|
78
268
|
readonly issues?: undefined;
|
|
79
269
|
} | {
|
|
80
|
-
readonly issues:
|
|
270
|
+
readonly issues: readonly StandardIssue[];
|
|
81
271
|
};
|
|
82
272
|
/** A schema that follows the Standard Schema interface, such as a zod object. */
|
|
83
273
|
type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
@@ -137,12 +327,25 @@ export declare function runtimeEnv<Schema extends StandardSchemaV1>(schema: Sche
|
|
|
137
327
|
* Gzips text responses and flushes after each chunk, so a streamed page shell
|
|
138
328
|
* or a server-sent event reaches the client at once. `hono/compress` holds a
|
|
139
329
|
* stream until it ends. Skips a response that is already encoded, a partial
|
|
140
|
-
* response, and one marked `no-transform`.
|
|
330
|
+
* response, and one marked `no-transform`. It sets `Vary: Accept-Encoding` on
|
|
331
|
+
* each response. The host gives the gzip stream. On a host with none, the
|
|
332
|
+
* plugin does nothing.
|
|
141
333
|
*
|
|
142
334
|
* @example
|
|
143
335
|
* createServer({ plugins: [requestId(), accessLog(), streamingCompress()] });
|
|
144
336
|
*/
|
|
145
337
|
export declare function streamingCompress(): Plugin;
|
|
338
|
+
/**
|
|
339
|
+
* The request ID and logger of the request that runs. It gives `undefined`
|
|
340
|
+
* outside a server request, such as in a prerender pass, or on a host with no
|
|
341
|
+
* request storage.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* export async function loader() {
|
|
345
|
+
* requestContext()?.logger.info("loading the dashboard");
|
|
346
|
+
* }
|
|
347
|
+
*/
|
|
348
|
+
export declare function requestContext(): RequestContext | undefined;
|
|
146
349
|
/**
|
|
147
350
|
* A signal that aborts when the server starts to shut down. Read it for each
|
|
148
351
|
* request: each start of a server makes a new one. A handler that
|
|
@@ -154,23 +357,5 @@ export declare function streamingCompress(): Plugin;
|
|
|
154
357
|
* shutdownSignal().addEventListener("abort", () => clearInterval(timer), { once: true });
|
|
155
358
|
*/
|
|
156
359
|
export declare function shutdownSignal(): AbortSignal;
|
|
157
|
-
|
|
158
|
-
type TcpOptions = {
|
|
159
|
-
/** @default the `PORT` environment variable, else 3000 */
|
|
160
|
-
port?: number;
|
|
161
|
-
/** @default the `HOST` environment variable, else every interface */
|
|
162
|
-
host?: string;
|
|
163
|
-
/** @default 95000 */
|
|
164
|
-
idleTimeoutMs?: number;
|
|
165
|
-
};
|
|
166
|
-
/**
|
|
167
|
-
* The default listener: a TCP port, served by the runtime's own HTTP server
|
|
168
|
-
* (`node:http` on Node, `Bun.serve` on Bun, `Deno.serve` on Deno). It reads
|
|
169
|
-
* `PORT` and `HOST` when it starts.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* createServer({ listeners: [tcp({ port: 8080 })] });
|
|
173
|
-
*/
|
|
174
|
-
export declare function tcp({ port, host, idleTimeoutMs }?: TcpOptions): Listener;
|
|
175
|
-
export { type AccessLogOptions, type AppServer, type AppServerEntry, type AppServerEnv, type BuildIdOptions, type CreateServerOptions, type DefaultPluginsOptions, type EventStreamOptions, type EventStreamSink, type FetchHandler, type FrameworkAdapter, type InferOutput, type Listener, type ListenerBindings, type LogLevel, type LogSink, type NodeMiddleware, type Plugin, type PrerenderedOptions, type RequestIdOptions, type RequestLogger, type RunningServer, type RuntimeEnv, type RuntimeEnvOptions, type ServerBindings, type ServerSentEvent, type SetupInfo, type StandardSchemaV1, type StartedListener, type TcpOptions, accessLog, assets, createEntry, createServer, defaultPlugins, prerendered, requestId };
|
|
360
|
+
export type { AccessLogOptions, AppServer, AppServerEntry, AppServerEnv, BuildIdOptions, CreateEntryOptions, CreateServerOptions, DefaultPluginsOptions, EventStreamOptions, EventStreamSink, FetchHandler, FileInfo, FrameworkRuntime, FrameworkRuntimeFactory, HostRuntime, InferOutput, Lifecycle, Listener, ListenerBindings, LogLevel, LogSink, Mode, Plugin, PrerenderedOptions, RequestContext, RequestIdOptions, RequestLogger, RequestStore, RunningServer, RuntimeEnv, RuntimeEnvOptions, ServerBindings, ServerSentEvent, SetupInfo, StandardSchemaV1, StartedListener, StaticFiles };
|
|
176
361
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { a as shutdownSignal, c as
|
|
1
|
+
import { n as jsonSink } from "./log-CsjaKM8U.js";
|
|
2
|
+
import { a as shutdownSignal, c as assets, d as accessLog, i as defaultPlugins, l as prerendered, o as requestContext, r as createServer, s as streamingCompress, t as createEntry, u as requestId } from "./entry-BkdUub2S.js";
|
|
3
3
|
|
|
4
|
-
// src/event-stream.ts
|
|
4
|
+
// src/core/event-stream.ts
|
|
5
5
|
function formatEvent({ data, event, id }) {
|
|
6
|
-
if (/[\r\n]
|
|
6
|
+
if (/[\r\n]/u.test(`${event ?? ""}${id ?? ""}`)) throw new TypeError("An event's `event` and `id` cannot contain a line break.");
|
|
7
7
|
return `${[
|
|
8
8
|
...event == null ? [] : [`event: ${event}`],
|
|
9
9
|
...id == null ? [] : [`id: ${id}`],
|
|
10
|
-
...data.split(/\r\n|\r|\n/).map((line) => `data: ${line}`)
|
|
10
|
+
...data.split(/\r\n|\r|\n/u).map((line) => `data: ${line}`)
|
|
11
11
|
].join("\n")}\n\n`;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -55,8 +55,10 @@ function eventStream({ signal, heartbeatMs = 15e3, headers }, produce) {
|
|
|
55
55
|
close();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
Promise.resolve().then(() => produce({
|
|
59
|
-
send: (event) =>
|
|
58
|
+
Promise.resolve().then(async () => produce({
|
|
59
|
+
send: (event) => {
|
|
60
|
+
write(formatEvent(event));
|
|
61
|
+
},
|
|
60
62
|
signal: stopSignal
|
|
61
63
|
})).then(close, (error) => {
|
|
62
64
|
closed = true;
|
|
@@ -77,26 +79,35 @@ function eventStream({ signal, heartbeatMs = 15e3, headers }, produce) {
|
|
|
77
79
|
return new Response(body, { headers: responseHeaders });
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
// src/plugins/build-id.ts
|
|
82
|
+
// src/core/plugins/build-id.ts
|
|
83
|
+
/** The data check before `setup` runs. */
|
|
84
|
+
function noDataRequests() {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
81
87
|
/**
|
|
82
|
-
* Sets a build ID header on documents and
|
|
83
|
-
* a client can see that a deploy
|
|
88
|
+
* Sets a build ID header on documents and on the framework's data responses,
|
|
89
|
+
* such as React Router `.data` files, so a client can see that a deploy
|
|
90
|
+
* happened under it.
|
|
84
91
|
*
|
|
85
92
|
* @example
|
|
86
93
|
* buildId({ value: env.values.PUBLIC_APP_VERSION });
|
|
87
94
|
*/
|
|
88
95
|
function buildId({ header = "X-Build-Id", value }) {
|
|
96
|
+
let isDataRequest = noDataRequests;
|
|
89
97
|
return {
|
|
90
98
|
name: "build-id",
|
|
99
|
+
setup: (info) => {
|
|
100
|
+
({isDataRequest} = info);
|
|
101
|
+
},
|
|
91
102
|
etagPart: () => value,
|
|
92
103
|
middleware: async (context, next) => {
|
|
93
104
|
await next();
|
|
94
|
-
if ((context.res.headers.get("Content-Type")?.startsWith("text/html") ?? false) || context.req.path
|
|
105
|
+
if ((context.res.headers.get("Content-Type")?.startsWith("text/html") ?? false) || isDataRequest(context.req.path)) context.header(header, value);
|
|
95
106
|
}
|
|
96
107
|
};
|
|
97
108
|
}
|
|
98
109
|
|
|
99
|
-
// src/plugins/runtime-env.ts
|
|
110
|
+
// src/core/plugins/runtime-env.ts
|
|
100
111
|
/** The `id` of the JSON `<script>` that carries the public values into each HTML document. */
|
|
101
112
|
const PUBLIC_ENV_SCRIPT_ID = "app-server-public-env";
|
|
102
113
|
/** Stops the search for `</head>` after this many characters, so a page with none still streams. */
|
|
@@ -107,7 +118,7 @@ function formatIssue(issue) {
|
|
|
107
118
|
}
|
|
108
119
|
/** A JSON data block. Escaping `<` keeps a value from closing the `<script>`. */
|
|
109
120
|
function publicEnvScript(values) {
|
|
110
|
-
const json = JSON.stringify(values).replaceAll("<",
|
|
121
|
+
const json = JSON.stringify(values).replaceAll("<", String.raw`\u003c`);
|
|
111
122
|
return `<script id="${PUBLIC_ENV_SCRIPT_ID}" type="application/json">${json}<\/script>`;
|
|
112
123
|
}
|
|
113
124
|
/** Inserts `html` before the first `</head>` of a streamed document. The rest streams as is. */
|
|
@@ -123,7 +134,7 @@ function injectBeforeHeadEnd(body, html) {
|
|
|
123
134
|
return;
|
|
124
135
|
}
|
|
125
136
|
pending += text;
|
|
126
|
-
const index = pending.search(/<\/head>/
|
|
137
|
+
const index = pending.search(/<\/head>/iu);
|
|
127
138
|
if (index !== -1) {
|
|
128
139
|
controller.enqueue(encoder.encode(`${pending.slice(0, index)}${html}${pending.slice(index)}`));
|
|
129
140
|
pending = void 0;
|
|
@@ -198,5 +209,5 @@ function runtimeEnv(schema, { source = process.env, publicPrefix = "PUBLIC_" } =
|
|
|
198
209
|
};
|
|
199
210
|
}
|
|
200
211
|
|
|
201
|
-
export { PUBLIC_ENV_SCRIPT_ID, accessLog, assets, buildId, createEntry, createServer, defaultPlugins, eventStream, jsonSink, prerendered, requestId, runtimeEnv, shutdownSignal, streamingCompress
|
|
212
|
+
export { PUBLIC_ENV_SCRIPT_ID, accessLog, assets, buildId, createEntry, createServer, defaultPlugins, eventStream, jsonSink, prerendered, requestContext, requestId, runtimeEnv, shutdownSignal, streamingCompress };
|
|
202
213
|
//# sourceMappingURL=index.js.map
|