@ngrok/app-server 0.2.0 → 0.3.1

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.
Files changed (108) hide show
  1. package/README.md +652 -77
  2. package/dist/build-id-C6sYO9Yp.js +126 -0
  3. package/dist/build-id-C6sYO9Yp.js.map +1 -0
  4. package/dist/{build-manifest-8NfD1wnO.js → build-manifest-UDNk81Ce.js} +24 -6
  5. package/dist/build-manifest-UDNk81Ce.js.map +1 -0
  6. package/dist/cli.js +45 -25
  7. package/dist/cli.js.map +1 -1
  8. package/dist/client-browser.d.ts +12 -0
  9. package/dist/client-browser.js +3 -0
  10. package/dist/client.d.ts +21 -0
  11. package/dist/client.js +27 -0
  12. package/dist/client.js.map +1 -0
  13. package/dist/compression-7_gToa8R.js +97 -0
  14. package/dist/compression-7_gToa8R.js.map +1 -0
  15. package/dist/create-server-DkTeIJ8L.js +1409 -0
  16. package/dist/create-server-DkTeIJ8L.js.map +1 -0
  17. package/dist/{deno-DNRgzHrk.js → deno-aqhikNMG.js} +2 -2
  18. package/dist/deno-aqhikNMG.js.map +1 -0
  19. package/dist/entry-CM6Ma-Tv.d.ts +626 -0
  20. package/dist/entry-CenmvESk.js +116 -0
  21. package/dist/entry-CenmvESk.js.map +1 -0
  22. package/dist/gzip-Doi4wqjX.js +294 -0
  23. package/dist/gzip-Doi4wqjX.js.map +1 -0
  24. package/dist/header-hook-Vzw9J9BY.js +159 -0
  25. package/dist/header-hook-Vzw9J9BY.js.map +1 -0
  26. package/dist/{index-oSE-tYRW.d.ts → index-Bo5G9LuQ.d.ts} +53 -14
  27. package/dist/index.d.ts +99 -269
  28. package/dist/index.js +47 -59
  29. package/dist/index.js.map +1 -1
  30. package/dist/listen-options-7TaXjyrk.js.map +1 -1
  31. package/dist/{load-entry-C03qqmhr.js → load-entry-CmkdlmDX.js} +8 -4
  32. package/dist/{load-entry-C03qqmhr.js.map → load-entry-CmkdlmDX.js.map} +1 -1
  33. package/dist/log-BP6xXXZl.js +122 -0
  34. package/dist/log-BP6xXXZl.js.map +1 -0
  35. package/dist/node-BFH82eeL.js +333 -0
  36. package/dist/node-BFH82eeL.js.map +1 -0
  37. package/dist/node-tBVQPjQv.js +41 -0
  38. package/dist/node-tBVQPjQv.js.map +1 -0
  39. package/dist/node-vite.d.ts +5 -4
  40. package/dist/node-vite.js +2 -17
  41. package/dist/node.d.ts +23 -4
  42. package/dist/node.js +2 -2
  43. package/dist/react-router-vite.d.ts +4 -3
  44. package/dist/react-router-vite.js +2 -20
  45. package/dist/react-router.d.ts +1 -1
  46. package/dist/react-router.js +8 -7
  47. package/dist/react-router.js.map +1 -1
  48. package/dist/request-context-BtQ87VYb.js +40 -0
  49. package/dist/request-context-BtQ87VYb.js.map +1 -0
  50. package/dist/response-edge-Bc1-C_Cx.js +327 -0
  51. package/dist/response-edge-Bc1-C_Cx.js.map +1 -0
  52. package/dist/response-writer-B7FoJjEE.js +289 -0
  53. package/dist/response-writer-B7FoJjEE.js.map +1 -0
  54. package/dist/script-hashes-hqUk6kG7.js +53 -0
  55. package/dist/script-hashes-hqUk6kG7.js.map +1 -0
  56. package/dist/{serve-Cleo8RMO.js → serve-Cc-ADdhZ.js} +3 -3
  57. package/dist/{serve-Cleo8RMO.js.map → serve-Cc-ADdhZ.js.map} +1 -1
  58. package/dist/stale-build-navigation-PnMLtTF8.js +339 -0
  59. package/dist/stale-build-navigation-PnMLtTF8.js.map +1 -0
  60. package/dist/stale-build-navigation-ypV7Ow4o.d.ts +141 -0
  61. package/dist/{start-CINALHxy.js → start-Cb3kknlF.js} +14 -19
  62. package/dist/start-Cb3kknlF.js.map +1 -0
  63. package/dist/static-files-Beju9riB.js +302 -0
  64. package/dist/static-files-Beju9riB.js.map +1 -0
  65. package/dist/tanstack-start-vite.d.ts +6 -5
  66. package/dist/tanstack-start-vite.js +2 -23
  67. package/dist/tanstack-start.d.ts +19 -2
  68. package/dist/tanstack-start.js +5 -14
  69. package/dist/tanstack-start.js.map +1 -1
  70. package/dist/{tcp-C-9AmFuM.js → tcp-Dd1Mt6sN.js} +6 -5
  71. package/dist/{tcp-C-9AmFuM.js.map → tcp-Dd1Mt6sN.js.map} +1 -1
  72. package/dist/trailing-slash-DX7NB88H.d.ts +36 -0
  73. package/dist/types-DLYxYS6M.d.ts +392 -0
  74. package/dist/vercel-vite.d.ts +35 -0
  75. package/dist/vercel-vite.js +142 -0
  76. package/dist/vercel-vite.js.map +1 -0
  77. package/dist/vercel.d.ts +35 -0
  78. package/dist/vercel.js +89 -0
  79. package/dist/vercel.js.map +1 -0
  80. package/dist/vite-B-GfswoH.js +22 -0
  81. package/dist/vite-B-GfswoH.js.map +1 -0
  82. package/dist/vite-D4hfj3ph.js +19 -0
  83. package/dist/vite-D4hfj3ph.js.map +1 -0
  84. package/dist/vite-DyrhyKEr.js +25 -0
  85. package/dist/vite-DyrhyKEr.js.map +1 -0
  86. package/dist/vite-iioAoxSt.js +752 -0
  87. package/dist/vite-iioAoxSt.js.map +1 -0
  88. package/dist/vite.d.ts +2 -2
  89. package/dist/vite.js +1 -1
  90. package/package.json +25 -4
  91. package/dist/build-manifest-8NfD1wnO.js.map +0 -1
  92. package/dist/deno-DNRgzHrk.js.map +0 -1
  93. package/dist/entry-BkdUub2S.js +0 -638
  94. package/dist/entry-BkdUub2S.js.map +0 -1
  95. package/dist/log-CsjaKM8U.js +0 -59
  96. package/dist/log-CsjaKM8U.js.map +0 -1
  97. package/dist/node-CG7qXuWZ.js +0 -58
  98. package/dist/node-CG7qXuWZ.js.map +0 -1
  99. package/dist/node-YWPGmzAk.js +0 -215
  100. package/dist/node-YWPGmzAk.js.map +0 -1
  101. package/dist/node-ZMowKZDB.js +0 -3
  102. package/dist/node-vite.js.map +0 -1
  103. package/dist/react-router-vite.js.map +0 -1
  104. package/dist/start-CINALHxy.js.map +0 -1
  105. package/dist/tanstack-start-vite.js.map +0 -1
  106. package/dist/types-BfCkS7kQ.d.ts +0 -203
  107. package/dist/vite-mYZ2Y69u.js +0 -144
  108. package/dist/vite-mYZ2Y69u.js.map +0 -1
@@ -0,0 +1,302 @@
1
+ import { r as hookedHeaders } from "./header-hook-Vzw9J9BY.js";
2
+ import { i as forbidsTransform, o as preferredEncoding, r as copyName, t as COPY_ENCODINGS } from "./compression-7_gToa8R.js";
3
+ import { getMimeType } from "hono/utils/mime";
4
+
5
+ // src/core/vary.ts
6
+ /**
7
+ * A `Vary` value with `name` added, or `undefined` when `vary` already covers
8
+ * it. The existing values stay as they are.
9
+ *
10
+ * @example
11
+ * withVary("Accept", "Accept-Encoding"); // => "Accept, Accept-Encoding"
12
+ * withVary("accept-encoding", "Accept-Encoding"); // => undefined
13
+ */
14
+ function withVary(vary, name) {
15
+ if (vary == null || vary.trim() === "") return name;
16
+ const values = new Set(vary.split(",").map((value) => value.trim().toLowerCase()));
17
+ return values.has(name.toLowerCase()) || values.has("*") ? void 0 : `${vary}, ${name}`;
18
+ }
19
+
20
+ // src/core/static-files.ts
21
+ /** The content types that `mime` lacks and that no framework owns. */
22
+ const CORE_CONTENT_TYPES = { ".md": "text/markdown; charset=utf-8" };
23
+ /**
24
+ * Whether a URL path names a dotfile or goes through a dot directory.
25
+ * `/.well-known/` stays reachable.
26
+ *
27
+ * @example
28
+ * hasDotSegment("/assets/.private/key.json"); // => true
29
+ * hasDotSegment("/.well-known/security.txt"); // => false
30
+ */
31
+ function hasDotSegment(path) {
32
+ return path.split("/").some((segment, index) => segment.startsWith(".") && !(index === 1 && segment === ".well-known"));
33
+ }
34
+ /**
35
+ * Whether a decoded URL path, such as Hono's `context.req.path`, can name a
36
+ * file of the client build. Dotfiles, paths that leave the client build, and
37
+ * a second URL for a file, such as `/a//b` or `/a/index.html`, cannot.
38
+ */
39
+ function isFilePath(path) {
40
+ return path.startsWith("/") && !path.includes("\0") && !path.includes("\\") && !path.split("/").includes("..") && !path.includes("//") && !path.endsWith("/index.html") && !hasDotSegment(path);
41
+ }
42
+ /**
43
+ * Finds the file in `files` that answers a decoded URL path, such as Hono's
44
+ * `context.req.path`. A directory answers with its `index.html` and no
45
+ * redirect, so a prerendered page keeps its URL. A path that fails
46
+ * `isFilePath` finds nothing.
47
+ *
48
+ * Each file has one URL, because the headers for a file are keyed by that
49
+ * URL. So `/a//b`, `/a/index.html`, and `/a%2Fb` find nothing. Hono decodes
50
+ * the path but keeps an encoded `/` as `%2F`, so this function does not
51
+ * decode it again.
52
+ *
53
+ * @example
54
+ * await findStaticFile(files, "/components/button");
55
+ * // => { path: "/components/button/index.html", size: 5120, mtimeMs: 1761652800000 }
56
+ */
57
+ async function findStaticFile(files, path) {
58
+ if (!isFilePath(path)) return;
59
+ const info = await files.stat(path);
60
+ if (info?.kind === "file") return {
61
+ path,
62
+ size: info.size,
63
+ mtimeMs: info.mtimeMs
64
+ };
65
+ if (info?.kind === "directory") {
66
+ const index = `${path.replace(/\/$/u, "")}/index.html`;
67
+ const indexInfo = await files.stat(index);
68
+ if (indexInfo?.kind === "file") return {
69
+ path: index,
70
+ size: indexInfo.size,
71
+ mtimeMs: indexInfo.mtimeMs
72
+ };
73
+ }
74
+ }
75
+ /** The content type of a file, by its extension. `contentTypes` win over `mime`. */
76
+ function contentType(path, contentTypes) {
77
+ const extension = /\.[^./]+$/u.exec(path)?.[0] ?? "";
78
+ return contentTypes[extension] ?? CORE_CONTENT_TYPES[extension] ?? getMimeType(path) ?? "application/octet-stream";
79
+ }
80
+ /** An ETag without its weak prefix, for the weak comparison that `If-None-Match` uses. */
81
+ function opaqueTag(etag) {
82
+ return etag.trim().replace(/^W\//u, "");
83
+ }
84
+ /** Whether an `If-None-Match` header lists an ETag. */
85
+ function matchesEtag(ifNoneMatch, etag) {
86
+ return ifNoneMatch?.split(",").some((candidate) => {
87
+ const trimmed = candidate.trim();
88
+ return trimmed === "*" || opaqueTag(trimmed) === opaqueTag(etag);
89
+ }) ?? false;
90
+ }
91
+ /**
92
+ * The last `etagParts` and their hash. Why one entry: each request has the
93
+ * same parts for the life of the process.
94
+ */
95
+ let lastParts;
96
+ /** A short hash of the request's `etagParts`. */
97
+ async function partsHash(parts) {
98
+ const key = parts.join("\0");
99
+ if (lastParts?.key === key) return lastParts.hash;
100
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(key));
101
+ const hash = btoa(String.fromCodePoint(...new Uint8Array(digest))).replaceAll("+", "-").replaceAll("/", "_").slice(0, 16);
102
+ lastParts = {
103
+ key,
104
+ hash
105
+ };
106
+ return hash;
107
+ }
108
+ /**
109
+ * A weak ETag from a file's size, its modification time, the request's
110
+ * `etagParts`, and the encoding of the body. Why the encoding: after a 304,
111
+ * a cache that holds more than one encoding of the file picks the stored
112
+ * response by its ETag (RFC 9111, section 4.3.4).
113
+ */
114
+ async function fileEtag(file, parts, encoding) {
115
+ return `W/"${[
116
+ file.size.toString(16),
117
+ Math.trunc(file.mtimeMs).toString(16),
118
+ ...parts.length === 0 ? [] : [await partsHash(parts)],
119
+ ...encoding == null ? [] : [encoding]
120
+ ].join("-")}"`;
121
+ }
122
+ /**
123
+ * The byte range that a `Range` header asks for in a file of `size` bytes.
124
+ * It gives `"unsatisfiable"` for a range that starts after the end of the
125
+ * file, and `undefined` for a header to ignore: a header that is not valid,
126
+ * or one with more than one range.
127
+ *
128
+ * @example
129
+ * byteRange("bytes=-100", 1000); // => { start: 900, end: 999 }
130
+ */
131
+ function byteRange(header, size) {
132
+ const groups = /^bytes=(?<first>\d*)-(?<last>\d*)$/u.exec(header.trim())?.groups;
133
+ const first = groups?.first ?? "";
134
+ const last = groups?.last ?? "";
135
+ if (first === "" && last === "") return;
136
+ if (first === "") {
137
+ const suffix = Number(last);
138
+ return suffix === 0 || size === 0 ? "unsatisfiable" : {
139
+ start: Math.max(0, size - suffix),
140
+ end: size - 1
141
+ };
142
+ }
143
+ const start = Number(first);
144
+ const end = last === "" ? Number.POSITIVE_INFINITY : Number(last);
145
+ if (end < start) return;
146
+ return start >= size ? "unsatisfiable" : {
147
+ start,
148
+ end: Math.min(end, size - 1)
149
+ };
150
+ }
151
+ /** Why these caps: they hold the hashed chunks of a typical app, and they limit the memory of each process. */
152
+ const KEPT_FILE_BYTES = 262144;
153
+ const KEPT_TOTAL_BYTES = 33554432;
154
+ /**
155
+ * `files` that keep the bytes of each small file in memory after the first
156
+ * read, up to {@link KEPT_TOTAL_BYTES} in all. Use it only for files that
157
+ * do not change while the server runs, such as a `StaticFiles.snapshot()`.
158
+ *
159
+ * @example
160
+ * const files = keptFiles(await nodeFiles("build/client").snapshot());
161
+ */
162
+ function keptFiles(files) {
163
+ const kept = /* @__PURE__ */ new Map();
164
+ let total = 0;
165
+ return {
166
+ stat: files.stat,
167
+ open: async (path, range) => {
168
+ let bytes = kept.get(path);
169
+ const info = bytes == null ? await files.stat(path) : void 0;
170
+ bytes ??= kept.get(path);
171
+ if (bytes == null) {
172
+ if (info?.kind !== "file" || info.size > KEPT_FILE_BYTES || total + info.size > KEPT_TOTAL_BYTES) return files.open(path, range);
173
+ total += info.size;
174
+ bytes = files.open(path, {
175
+ start: 0,
176
+ end: info.size - 1
177
+ }).then(async (stream) => new Uint8Array(await new Response(stream).arrayBuffer()));
178
+ kept.set(path, bytes);
179
+ bytes.catch(() => {
180
+ kept.delete(path);
181
+ total -= info.size;
182
+ });
183
+ }
184
+ const chunk = (await bytes).slice(range?.start ?? 0, range == null ? void 0 : range.end + 1);
185
+ return new ReadableStream({ start(controller) {
186
+ controller.enqueue(chunk);
187
+ controller.close();
188
+ } });
189
+ }
190
+ };
191
+ }
192
+ /**
193
+ * The copy of the file at `path` that the request prefers, from the copies
194
+ * that the build wrote. When a copy exists, it adds `Accept-Encoding` to the
195
+ * `Vary` in `headers`, also for a request that gets no copy.
196
+ */
197
+ async function preferredCopy(context, { files, path, headers }) {
198
+ if (headers.has("Content-Encoding") || context.get("rewritesHtml") === true && (headers.get("Content-Type")?.startsWith("text/html") ?? false)) return;
199
+ const copies = [];
200
+ for (const encoding of COPY_ENCODINGS) {
201
+ const copyPath = path.replace(/[^/]*$/u, (name) => copyName(name, encoding));
202
+ const info = await files.stat(copyPath);
203
+ if (info?.kind === "file") copies.push({
204
+ path: copyPath,
205
+ size: info.size,
206
+ mtimeMs: info.mtimeMs,
207
+ encoding
208
+ });
209
+ }
210
+ if (copies.length === 0) return;
211
+ const vary = withVary(headers.get("Vary"), "Accept-Encoding");
212
+ if (vary != null) headers.set("Vary", vary);
213
+ if (forbidsTransform(hookedHeaders(context, headers).get("Cache-Control"))) return;
214
+ const encoding = preferredEncoding(context.req.header("Accept-Encoding"), copies.map((copy) => copy.encoding));
215
+ return copies.find((copy) => copy.encoding === encoding);
216
+ }
217
+ /**
218
+ * All bytes of a file. Why the size as a range: the body then never has more
219
+ * bytes than its `Content-Length`, even when the file grew after `stat`, and
220
+ * a small file reads into a small buffer.
221
+ */
222
+ async function wholeFile(files, file) {
223
+ return file.size === 0 ? null : files.open(file.path, {
224
+ start: 0,
225
+ end: file.size - 1
226
+ });
227
+ }
228
+ /**
229
+ * The response for a static file, with a weak ETag from its size,
230
+ * modification time, the request's `etagParts`, and its encoding. A matching
231
+ * `If-None-Match` gets a 304, and `HEAD` gets the headers only.
232
+ *
233
+ * A GET with one `bytes` range gets a 206 with those bytes, and a range
234
+ * after the end of the file gets a 416. A request with `If-Range` gets the
235
+ * full file. Why: the ETag is weak, and `If-Range` needs a strong match. An
236
+ * HTML file gets no ranges.
237
+ *
238
+ * When the build wrote a compressed copy of the file (`.<file>.br` or
239
+ * `.<file>.gz`), the response gets `Vary: Accept-Encoding`. A request gets
240
+ * the copy that its `Accept-Encoding` prefers, brotli before gzip, with its
241
+ * `Content-Encoding`, an ETag for that encoding, and no range. A response
242
+ * marked `no-transform`, also by the header hook of an earlier stage, and a
243
+ * response that `headers` encode, never get a copy. An HTML file gets no
244
+ * copy when an earlier stage sets `rewritesHtml`.
245
+ *
246
+ * @example
247
+ * const file = await findStaticFile(files, "/llms.txt");
248
+ * if (file != null) {
249
+ * return staticResponse(context, { files, file, headers: {}, contentTypes: {} });
250
+ * }
251
+ */
252
+ async function staticResponse(context, { files, file, headers, contentTypes }) {
253
+ const responseHeaders = new Headers({ "Content-Type": contentType(file.path, contentTypes) });
254
+ for (const [name, value] of Object.entries(headers)) responseHeaders.set(name, value);
255
+ const html = responseHeaders.get("Content-Type")?.startsWith("text/html") ?? false;
256
+ if (html) context.set("staticDocument", file.path);
257
+ const copy = await preferredCopy(context, {
258
+ files,
259
+ path: file.path,
260
+ headers: responseHeaders
261
+ });
262
+ const etag = responseHeaders.get("ETag") ?? await fileEtag(file, context.get("etagParts") ?? [], copy?.encoding);
263
+ responseHeaders.set("ETag", etag);
264
+ if (matchesEtag(context.req.header("If-None-Match"), etag)) {
265
+ responseHeaders.delete("Content-Type");
266
+ return new Response(null, {
267
+ status: 304,
268
+ headers: responseHeaders
269
+ });
270
+ }
271
+ if (copy != null) {
272
+ responseHeaders.set("Content-Encoding", copy.encoding);
273
+ responseHeaders.set("Content-Length", String(copy.size));
274
+ const body = context.req.method === "HEAD" ? null : await wholeFile(files, copy);
275
+ return new Response(body, { headers: responseHeaders });
276
+ }
277
+ if (!html) responseHeaders.set("Accept-Ranges", "bytes");
278
+ responseHeaders.set("Content-Length", String(file.size));
279
+ if (context.req.method === "HEAD") return new Response(null, { headers: responseHeaders });
280
+ const rangeHeader = context.req.header("Range");
281
+ const range = html || rangeHeader == null || context.req.header("If-Range") != null ? void 0 : byteRange(rangeHeader, file.size);
282
+ if (range === "unsatisfiable") {
283
+ responseHeaders.set("Content-Range", `bytes */${file.size}`);
284
+ responseHeaders.delete("Content-Length");
285
+ return new Response(null, {
286
+ status: 416,
287
+ headers: responseHeaders
288
+ });
289
+ }
290
+ if (range != null) {
291
+ responseHeaders.set("Content-Range", `bytes ${range.start}-${range.end}/${file.size}`);
292
+ responseHeaders.set("Content-Length", String(range.end - range.start + 1));
293
+ return new Response(await files.open(file.path, range), {
294
+ status: 206,
295
+ headers: responseHeaders
296
+ });
297
+ }
298
+ return new Response(await wholeFile(files, file), { headers: responseHeaders });
299
+ }
300
+
301
+ export { keptFiles as a, isFilePath as i, findStaticFile as n, staticResponse as o, hasDotSegment as r, withVary as s, contentType as t };
302
+ //# sourceMappingURL=static-files-Beju9riB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-files-Beju9riB.js","names":[],"sources":["../src/core/vary.ts","../src/core/static-files.ts"],"sourcesContent":["/**\n * A `Vary` value with `name` added, or `undefined` when `vary` already covers\n * it. The existing values stay as they are.\n *\n * @example\n * withVary(\"Accept\", \"Accept-Encoding\"); // => \"Accept, Accept-Encoding\"\n * withVary(\"accept-encoding\", \"Accept-Encoding\"); // => undefined\n */\nexport function withVary(vary: string | null, name: string): string | undefined {\n\tif (vary == null || vary.trim() === \"\") {\n\t\treturn name;\n\t}\n\tconst values = new Set(vary.split(\",\").map((value) => value.trim().toLowerCase()));\n\treturn values.has(name.toLowerCase()) || values.has(\"*\") ? undefined : `${vary}, ${name}`;\n}\n","import type { Context } from \"hono\";\nimport { getMimeType } from \"hono/utils/mime\";\nimport { COPY_ENCODINGS, copyName, forbidsTransform, preferredEncoding } from \"./compression.js\";\nimport type { Encoding } from \"./compression.js\";\nimport { hookedHeaders } from \"./header-hook.js\";\nimport type { AppServerEnv, ByteRange, StaticFiles } from \"./types.js\";\nimport { withVary } from \"./vary.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 *\n * @example\n * hasDotSegment(\"/assets/.private/key.json\"); // => true\n * hasDotSegment(\"/.well-known/security.txt\"); // => false\n */\nexport function 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 * Whether a decoded URL path, such as Hono's `context.req.path`, can name a\n * file of the client build. Dotfiles, paths that leave the client build, and\n * a second URL for a file, such as `/a//b` or `/a/index.html`, cannot.\n */\nexport function isFilePath(path: string): boolean {\n\treturn (\n\t\tpath.startsWith(\"/\") &&\n\t\t!path.includes(\"\\0\") &&\n\t\t!path.includes(\"\\\\\") &&\n\t\t!path.split(\"/\").includes(\"..\") &&\n\t\t!path.includes(\"//\") &&\n\t\t!path.endsWith(\"/index.html\") &&\n\t\t!hasDotSegment(path)\n\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. A path that fails\n * `isFilePath` finds 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 (!isFilePath(path)) {\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`. */\nexport function 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/**\n * The last `etagParts` and their hash. Why one entry: each request has the\n * same parts for the life of the process.\n */\nlet lastParts: { key: string; hash: string } | undefined;\n\n/** A short hash of the request's `etagParts`. */\nasync function partsHash(parts: readonly string[]): Promise<string> {\n\tconst key = parts.join(\"\\0\");\n\tif (lastParts?.key === key) {\n\t\treturn lastParts.hash;\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(key));\n\tconst hash = btoa(String.fromCodePoint(...new Uint8Array(digest)))\n\t\t.replaceAll(\"+\", \"-\")\n\t\t.replaceAll(\"/\", \"_\")\n\t\t.slice(0, 16);\n\tlastParts = { key, hash };\n\treturn hash;\n}\n\n/**\n * A weak ETag from a file's size, its modification time, the request's\n * `etagParts`, and the encoding of the body. Why the encoding: after a 304,\n * a cache that holds more than one encoding of the file picks the stored\n * response by its ETag (RFC 9111, section 4.3.4).\n */\nasync function fileEtag(\n\tfile: StaticFile,\n\tparts: readonly string[],\n\tencoding: Encoding | undefined,\n): Promise<string> {\n\tconst tag = [\n\t\tfile.size.toString(16),\n\t\tMath.trunc(file.mtimeMs).toString(16),\n\t\t...(parts.length === 0 ? [] : [await partsHash(parts)]),\n\t\t...(encoding == null ? [] : [encoding]),\n\t];\n\treturn `W/\"${tag.join(\"-\")}\"`;\n}\n\n/**\n * The byte range that a `Range` header asks for in a file of `size` bytes.\n * It gives `\"unsatisfiable\"` for a range that starts after the end of the\n * file, and `undefined` for a header to ignore: a header that is not valid,\n * or one with more than one range.\n *\n * @example\n * byteRange(\"bytes=-100\", 1000); // => { start: 900, end: 999 }\n */\nexport function byteRange(header: string, size: number): ByteRange | \"unsatisfiable\" | undefined {\n\tconst groups = /^bytes=(?<first>\\d*)-(?<last>\\d*)$/u.exec(header.trim())?.groups;\n\tconst first = groups?.first ?? \"\";\n\tconst last = groups?.last ?? \"\";\n\tif (first === \"\" && last === \"\") {\n\t\treturn undefined;\n\t}\n\tif (first === \"\") {\n\t\tconst suffix = Number(last);\n\t\treturn suffix === 0 || size === 0\n\t\t\t? \"unsatisfiable\"\n\t\t\t: { start: Math.max(0, size - suffix), end: size - 1 };\n\t}\n\tconst start = Number(first);\n\tconst end = last === \"\" ? Number.POSITIVE_INFINITY : Number(last);\n\tif (end < start) {\n\t\treturn undefined;\n\t}\n\treturn start >= size ? \"unsatisfiable\" : { start, end: Math.min(end, size - 1) };\n}\n\n/** Why these caps: they hold the hashed chunks of a typical app, and they limit the memory of each process. */\nconst KEPT_FILE_BYTES = 256 * 1024;\nconst KEPT_TOTAL_BYTES = 32 * 1024 * 1024;\n\n/**\n * `files` that keep the bytes of each small file in memory after the first\n * read, up to {@link KEPT_TOTAL_BYTES} in all. Use it only for files that\n * do not change while the server runs, such as a `StaticFiles.snapshot()`.\n *\n * @example\n * const files = keptFiles(await nodeFiles(\"build/client\").snapshot());\n */\nexport function keptFiles(files: StaticFiles): StaticFiles {\n\tconst kept = new Map<string, Promise<Uint8Array>>();\n\tlet total = 0;\n\treturn {\n\t\tstat: files.stat,\n\t\topen: async (path, range) => {\n\t\t\tlet bytes = kept.get(path);\n\t\t\tconst info = bytes == null ? await files.stat(path) : undefined;\n\t\t\t// Why again: another request can start to read the file during the `stat`.\n\t\t\tbytes ??= kept.get(path);\n\t\t\tif (bytes == null) {\n\t\t\t\tif (\n\t\t\t\t\tinfo?.kind !== \"file\" ||\n\t\t\t\t\tinfo.size > KEPT_FILE_BYTES ||\n\t\t\t\t\ttotal + info.size > KEPT_TOTAL_BYTES\n\t\t\t\t) {\n\t\t\t\t\treturn files.open(path, range);\n\t\t\t\t}\n\t\t\t\ttotal += info.size;\n\t\t\t\t// Why the size as a range: the kept bytes then match the `Content-Length` from the lookup.\n\t\t\t\tbytes = files\n\t\t\t\t\t.open(path, { start: 0, end: info.size - 1 })\n\t\t\t\t\t.then(async (stream) => new Uint8Array(await new Response(stream).arrayBuffer()));\n\t\t\t\tkept.set(path, bytes);\n\t\t\t\tbytes.catch(() => {\n\t\t\t\t\tkept.delete(path);\n\t\t\t\t\ttotal -= info.size;\n\t\t\t\t});\n\t\t\t}\n\t\t\t// Why a copy: a later stage can change the bytes that it reads.\n\t\t\tconst chunk = (await bytes).slice(\n\t\t\t\trange?.start ?? 0,\n\t\t\t\trange == null ? undefined : range.end + 1,\n\t\t\t);\n\t\t\treturn new ReadableStream<Uint8Array>({\n\t\t\t\tstart(controller) {\n\t\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t\t\tcontroller.close();\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t};\n}\n\n/** A compressed copy of a static file that the build wrote. */\ntype Copy = StaticFile & { encoding: Encoding };\n\n/**\n * The copy of the file at `path` that the request prefers, from the copies\n * that the build wrote. When a copy exists, it adds `Accept-Encoding` to the\n * `Vary` in `headers`, also for a request that gets no copy.\n */\nasync function preferredCopy(\n\tcontext: Context<AppServerEnv>,\n\t{ files, path, headers }: { files: StaticFiles; path: string; headers: Headers },\n): Promise<Copy | undefined> {\n\t// Why not for an encoded file: the copy would encode it again, under one `Content-Encoding`.\n\tif (\n\t\theaders.has(\"Content-Encoding\") ||\n\t\t(context.get(\"rewritesHtml\") === true &&\n\t\t\t(headers.get(\"Content-Type\")?.startsWith(\"text/html\") ?? false))\n\t) {\n\t\treturn undefined;\n\t}\n\tconst copies: Copy[] = [];\n\tfor (const encoding of COPY_ENCODINGS) {\n\t\tconst copyPath = path.replace(/[^/]*$/u, (name) => copyName(name, encoding));\n\t\t// oxlint-disable-next-line no-await-in-loop -- two lookups, and a snapshot answers each at once.\n\t\tconst info = await files.stat(copyPath);\n\t\tif (info?.kind === \"file\") {\n\t\t\tcopies.push({ path: copyPath, size: info.size, mtimeMs: info.mtimeMs, encoding });\n\t\t}\n\t}\n\tif (copies.length === 0) {\n\t\treturn undefined;\n\t}\n\tconst vary = withVary(headers.get(\"Vary\"), \"Accept-Encoding\");\n\tif (vary != null) {\n\t\theaders.set(\"Vary\", vary);\n\t}\n\tif (forbidsTransform(hookedHeaders(context, headers).get(\"Cache-Control\"))) {\n\t\treturn undefined;\n\t}\n\tconst encoding = preferredEncoding(\n\t\tcontext.req.header(\"Accept-Encoding\"),\n\t\tcopies.map((copy) => copy.encoding),\n\t);\n\treturn copies.find((copy) => copy.encoding === encoding);\n}\n\n/**\n * All bytes of a file. Why the size as a range: the body then never has more\n * bytes than its `Content-Length`, even when the file grew after `stat`, and\n * a small file reads into a small buffer.\n */\nasync function wholeFile(\n\tfiles: StaticFiles,\n\tfile: StaticFile,\n): Promise<ReadableStream<Uint8Array> | null> {\n\treturn file.size === 0 ? null : files.open(file.path, { start: 0, end: file.size - 1 });\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, the request's `etagParts`, and its encoding. A matching\n * `If-None-Match` gets a 304, and `HEAD` gets the headers only.\n *\n * A GET with one `bytes` range gets a 206 with those bytes, and a range\n * after the end of the file gets a 416. A request with `If-Range` gets the\n * full file. Why: the ETag is weak, and `If-Range` needs a strong match. An\n * HTML file gets no ranges.\n *\n * When the build wrote a compressed copy of the file (`.<file>.br` or\n * `.<file>.gz`), the response gets `Vary: Accept-Encoding`. A request gets\n * the copy that its `Accept-Encoding` prefers, brotli before gzip, with its\n * `Content-Encoding`, an ETag for that encoding, and no range. A response\n * marked `no-transform`, also by the header hook of an earlier stage, and a\n * response that `headers` encode, never get a copy. An HTML file gets no\n * copy when an earlier stage sets `rewritesHtml`.\n *\n * @example\n * const file = await findStaticFile(files, \"/llms.txt\");\n * if (file != null) {\n * return staticResponse(context, { files, file, headers: {}, contentTypes: {} });\n * }\n */\nexport async function staticResponse(\n\tcontext: Context<AppServerEnv>,\n\t{ files, file, headers, contentTypes }: StaticResponseOptions,\n): Promise<Response> {\n\tconst responseHeaders = new Headers({ \"Content-Type\": contentType(file.path, contentTypes) });\n\tfor (const [name, value] of Object.entries(headers)) {\n\t\tresponseHeaders.set(name, value);\n\t}\n\t// Why no ranges for HTML: a stage such as `runtimeEnv` can change the bytes of a page.\n\tconst html = responseHeaders.get(\"Content-Type\")?.startsWith(\"text/html\") ?? false;\n\tif (html) {\n\t\tcontext.set(\"staticDocument\", file.path);\n\t}\n\t// Why before the 304: a 304 sends the `Vary` and the ETag of its 200.\n\tconst copy = await preferredCopy(context, { files, path: file.path, headers: responseHeaders });\n\t// Why the header first: `headers` can replace the ETag.\n\tconst etag =\n\t\tresponseHeaders.get(\"ETag\") ??\n\t\t(await fileEtag(file, context.get(\"etagParts\") ?? [], copy?.encoding));\n\tresponseHeaders.set(\"ETag\", etag);\n\tif (matchesEtag(context.req.header(\"If-None-Match\"), etag)) {\n\t\tresponseHeaders.delete(\"Content-Type\");\n\t\treturn new Response(null, { status: 304, headers: responseHeaders });\n\t}\n\tif (copy != null) {\n\t\t// Why no ranges: a client asks for a range of the file, not of its compressed copy.\n\t\tresponseHeaders.set(\"Content-Encoding\", copy.encoding);\n\t\tresponseHeaders.set(\"Content-Length\", String(copy.size));\n\t\tconst body = context.req.method === \"HEAD\" ? null : await wholeFile(files, copy);\n\t\treturn new Response(body, { headers: responseHeaders });\n\t}\n\tif (!html) {\n\t\tresponseHeaders.set(\"Accept-Ranges\", \"bytes\");\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\tconst rangeHeader = context.req.header(\"Range\");\n\tconst range =\n\t\thtml || rangeHeader == null || context.req.header(\"If-Range\") != null\n\t\t\t? undefined\n\t\t\t: byteRange(rangeHeader, file.size);\n\tif (range === \"unsatisfiable\") {\n\t\tresponseHeaders.set(\"Content-Range\", `bytes */${file.size}`);\n\t\tresponseHeaders.delete(\"Content-Length\");\n\t\treturn new Response(null, { status: 416, headers: responseHeaders });\n\t}\n\tif (range != null) {\n\t\tresponseHeaders.set(\"Content-Range\", `bytes ${range.start}-${range.end}/${file.size}`);\n\t\tresponseHeaders.set(\"Content-Length\", String(range.end - range.start + 1));\n\t\treturn new Response(await files.open(file.path, range), {\n\t\t\tstatus: 206,\n\t\t\theaders: responseHeaders,\n\t\t});\n\t}\n\treturn new Response(await wholeFile(files, file), { headers: responseHeaders });\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAgB,SAAS,MAAqB,MAAkC;CAC/E,IAAI,QAAQ,QAAQ,KAAK,KAAK,MAAM,IACnC,OAAO;CAER,MAAM,SAAS,IAAI,IAAI,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,UAAU,MAAM,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC;CACjF,OAAO,OAAO,IAAI,KAAK,YAAY,CAAC,KAAK,OAAO,IAAI,GAAG,IAAI,SAAY,GAAG,KAAK,IAAI;AACpF;;;;ACGA,MAAM,qBAAuD,EAC5D,OAAO,+BACR;;;;;;;;;AAUA,SAAgB,cAAc,MAAuB;CACpD,OAAO,KACL,MAAM,GAAG,CAAC,CACV,MACC,SAAS,UAAU,QAAQ,WAAW,GAAG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MAAM,MAAM,QAAQ,CAAC,CAAC;EACzE,OAAO,IAAI,SAAS,MAAM,MAAM,KAAK,KAAK,MAAM,KAAK,GAAG;GACvD,QAAQ;GACR,SAAS;EACV,CAAC;CACF;CACA,OAAO,IAAI,SAAS,MAAM,UAAU,OAAO,IAAI,GAAG,EAAE,SAAS,gBAAgB,CAAC;AAC/E"}
@@ -1,11 +1,12 @@
1
- import { n as FrameworkBuild } from "./index-oSE-tYRW.js";
1
+ import { n as FrameworkBuild } from "./index-Bo5G9LuQ.js";
2
2
  /**
3
- * The build side of the TanStack Start adapter. In `app-server start`, Vite
4
- * runs in middleware mode, so Start skips its own SSR middleware, and the
5
- * pipeline renders each page.
3
+ * The build side of the TanStack Start adapter. `appServer` uses it when the
4
+ * Vite config has the TanStack Start plugin, so pass it only to override that.
5
+ * In `app-server start`, Vite runs in middleware mode, so Start skips its own
6
+ * SSR middleware, and the pipeline renders each page.
6
7
  *
7
8
  * @example
8
- * appServer({ framework: tanstackStartAdapter(), host: node(), app: "./server.ts" });
9
+ * appServer({ framework: tanstackStartAdapter() });
9
10
  */
10
11
  export declare function tanstackStartAdapter(): FrameworkBuild;
11
12
  //# sourceMappingURL=tanstack-start-vite.d.ts.map
@@ -1,24 +1,3 @@
1
- // src/tanstack-start/vite.ts
2
- /**
3
- * The build side of the TanStack Start adapter. In `app-server start`, Vite
4
- * runs in middleware mode, so Start skips its own SSR middleware, and the
5
- * pipeline renders each page.
6
- *
7
- * @example
8
- * appServer({ framework: tanstackStartAdapter(), host: node(), app: "./server.ts" });
9
- */
10
- function tanstackStartAdapter() {
11
- return {
12
- name: "tanstack-start",
13
- serverModule: "virtual:tanstack-start-server-entry",
14
- runtimeModule: "@ngrok/app-server/tanstack-start",
15
- runtimeOptions: "{ serverFnBase: process.env.TSS_SERVER_FN_BASE }",
16
- isPrerenderPass: () => process.env.TSS_PRERENDERING === "true",
17
- validate: (config) => {
18
- if (config.base !== "/") throw new Error(`@ngrok/app-server serves a build at "/" only, and this config has the base "${config.base}".`);
19
- }
20
- };
21
- }
1
+ import { t as tanstackStartAdapter } from "./vite-DyrhyKEr.js";
22
2
 
23
- export { tanstackStartAdapter };
24
- //# sourceMappingURL=tanstack-start-vite.js.map
3
+ export { tanstackStartAdapter };
@@ -1,7 +1,23 @@
1
- import { f as Mode, i as FrameworkRuntime } from "./types-BfCkS7kQ.js";
1
+ import { a as FrameworkRuntime, h as Mode } from "./types-DLYxYS6M.js";
2
+ import { t as TrailingSlash } from "./trailing-slash-DX7NB88H.js";
3
+ import { AnyRouter, RegisteredRouter } from "@tanstack/react-router";
4
+ /**
5
+ * The `trailingSlash` mode of a TanStack router: the app's registered router
6
+ * by default. A router with no `trailingSlash` has the mode `never`. With no
7
+ * registered router, it is every mode.
8
+ *
9
+ * Use it with `satisfies` on the server's mode. TypeScript then fails when the
10
+ * two modes differ, because different modes make the redirects loop.
11
+ *
12
+ * @example
13
+ * createServer({ plugins: defaultPlugins({ trailingSlash: "never" satisfies RouterTrailingSlash }) });
14
+ */
15
+ export type RouterTrailingSlash<TRouter extends AnyRouter = RegisteredRouter> = ModeOf<TRouter["options"]["trailingSlash"]>;
16
+ /** A router's `trailingSlash` type as a mode. Why the `any` test: `AnyRouter` has an `any` mode, and a conditional type makes `never` of it. */
17
+ type ModeOf<TOption> = 0 extends 1 & TOption ? TrailingSlash : NonNullable<TOption> extends (infer TMode extends TrailingSlash) ? TMode : TrailingSlash;
2
18
  /**
3
19
  * The run side of the TanStack Start adapter, for the module of Start's
4
- * server entry. Start gets the request ID and logger as `appServer` in its
20
+ * server entry. Start gets the `requestContext()` values as `appServer` in its
5
21
  * request context. The server reads the prerendered paths that the Vite plugin
6
22
  * recorded.
7
23
  *
@@ -14,4 +30,5 @@ export declare function runtime(serverModule: unknown, { serverFnBase }: {
14
30
  mode: Mode;
15
31
  serverFnBase?: string;
16
32
  }): FrameworkRuntime;
33
+ export {};
17
34
  //# sourceMappingURL=tanstack-start.d.ts.map
@@ -1,14 +1,8 @@
1
+ import { n as requestContextValues } from "./request-context-BtQ87VYb.js";
2
+
1
3
  // src/tanstack-start/index.ts
2
4
  /** The prefix of Start's server functions when the config sets none. */
3
5
  const DEFAULT_SERVER_FN_BASE = "/_serverFn/";
4
- /**
5
- * Whether a value is a `Response`. Why not only `instanceof`: on Node, the
6
- * listener replaces the global `Response`, but `fetch()` still returns the
7
- * original type.
8
- */
9
- function isResponse(value) {
10
- return value instanceof Response || Object.prototype.toString.call(value) === "[object Response]";
11
- }
12
6
  /** Whether a module's default export is a TanStack Start server entry. */
13
7
  function startServerEntry(module) {
14
8
  if (typeof module !== "object" || module == null) return;
@@ -18,13 +12,13 @@ function startServerEntry(module) {
18
12
  if (typeof fetch !== "function") return;
19
13
  return { fetch: async (request, options) => {
20
14
  const response = await Reflect.apply(fetch, entry, [request, options]);
21
- if (!isResponse(response)) throw new TypeError("The TanStack Start server entry did not return a Response.");
15
+ if (!(response instanceof Response)) throw new TypeError("The TanStack Start server entry did not return a Response.");
22
16
  return response;
23
17
  } };
24
18
  }
25
19
  /**
26
20
  * The run side of the TanStack Start adapter, for the module of Start's
27
- * server entry. Start gets the request ID and logger as `appServer` in its
21
+ * server entry. Start gets the `requestContext()` values as `appServer` in its
28
22
  * request context. The server reads the prerendered paths that the Vite plugin
29
23
  * recorded.
30
24
  *
@@ -39,10 +33,7 @@ function runtime(serverModule, { serverFnBase = DEFAULT_SERVER_FN_BASE }) {
39
33
  return {
40
34
  name: "tanstack-start",
41
35
  isDataRequest: (path) => path.startsWith(serverFnBase),
42
- fetch: async (request, context) => entry.fetch(request, { context: { appServer: {
43
- requestId: context.var.requestId,
44
- logger: context.var.logger
45
- } } })
36
+ fetch: async (request, context) => entry.fetch(request, { context: { appServer: requestContextValues(context) } })
46
37
  };
47
38
  }
48
39
 
@@ -1 +1 @@
1
- {"version":3,"file":"tanstack-start.js","names":[],"sources":["../src/tanstack-start/index.ts"],"sourcesContent":["import type { FrameworkRuntime, Mode } from \"../core/types.js\";\n\n/** The prefix of Start's server functions when the config sets none. */\nconst DEFAULT_SERVER_FN_BASE = \"/_serverFn/\";\n\n/** The part of a TanStack Start server entry that the adapter calls. */\ntype StartServerEntry = {\n\tfetch: (\n\t\trequest: Request,\n\t\toptions?: { context?: Record<string, unknown> },\n\t) => Response | Promise<Response>;\n};\n\n/**\n * Whether a value is a `Response`. Why not only `instanceof`: on Node, the\n * listener replaces the global `Response`, but `fetch()` still returns the\n * original type.\n */\nfunction isResponse(value: unknown): value is Response {\n\treturn value instanceof Response || Object.prototype.toString.call(value) === \"[object Response]\";\n}\n\n/** Whether a module's default export is a TanStack Start server entry. */\nfunction startServerEntry(module: unknown): StartServerEntry | undefined {\n\tif (typeof module !== \"object\" || module == null) {\n\t\treturn undefined;\n\t}\n\tconst entry: unknown = Reflect.get(module, \"default\");\n\tif (typeof entry !== \"object\" || entry == null || !(\"fetch\" in entry)) {\n\t\treturn undefined;\n\t}\n\tconst { fetch } = entry;\n\tif (typeof fetch !== \"function\") {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tfetch: async (request, options) => {\n\t\t\tconst response: unknown = await Reflect.apply(fetch, entry, [request, options]);\n\t\t\tif (!isResponse(response)) {\n\t\t\t\tthrow new TypeError(\"The TanStack Start server entry did not return a Response.\");\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n}\n\n/**\n * The run side of the TanStack Start adapter, for the module of Start's\n * server entry. Start gets the request ID and logger as `appServer` in its\n * request context. The server reads the prerendered paths that the Vite plugin\n * recorded.\n *\n * @param info.serverFnBase - The prefix of Start's server functions, `TSS_SERVER_FN_BASE`. The entry that the Vite plugin generates sets it.\n *\n * @example\n * const framework = runtime(await import(\"virtual:tanstack-start-server-entry\"), { mode: \"production\" });\n */\nexport function runtime(\n\tserverModule: unknown,\n\t{ serverFnBase = DEFAULT_SERVER_FN_BASE }: { mode: Mode; serverFnBase?: string },\n): FrameworkRuntime {\n\tconst entry = startServerEntry(serverModule);\n\tif (entry == null) {\n\t\tthrow new Error(\"The server module has no TanStack Start server entry as its default export.\");\n\t}\n\treturn {\n\t\tname: \"tanstack-start\",\n\t\tisDataRequest: (path) => path.startsWith(serverFnBase),\n\t\tfetch: async (request, context) =>\n\t\t\tentry.fetch(request, {\n\t\t\t\tcontext: {\n\t\t\t\t\tappServer: { requestId: context.var.requestId, logger: context.var.logger },\n\t\t\t\t},\n\t\t\t}),\n\t};\n}\n"],"mappings":";;AAGA,MAAM,yBAAyB;;;;;;AAe/B,SAAS,WAAW,OAAmC;CACtD,OAAO,iBAAiB,YAAY,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM;AAC/E;;AAGA,SAAS,iBAAiB,QAA+C;CACxE,IAAI,OAAO,WAAW,YAAY,UAAU,MAC3C;CAED,MAAM,QAAiB,QAAQ,IAAI,QAAQ,SAAS;CACpD,IAAI,OAAO,UAAU,YAAY,SAAS,QAAQ,EAAE,WAAW,QAC9D;CAED,MAAM,EAAE,UAAU;CAClB,IAAI,OAAO,UAAU,YACpB;CAED,OAAO,EACN,OAAO,OAAO,SAAS,YAAY;EAClC,MAAM,WAAoB,MAAM,QAAQ,MAAM,OAAO,OAAO,CAAC,SAAS,OAAO,CAAC;EAC9E,IAAI,CAAC,WAAW,QAAQ,GACvB,MAAM,IAAI,UAAU,4DAA4D;EAEjF,OAAO;CACR,EACD;AACD;;;;;;;;;;;;AAaA,SAAgB,QACf,cACA,EAAE,eAAe,0BACE;CACnB,MAAM,QAAQ,iBAAiB,YAAY;CAC3C,IAAI,SAAS,MACZ,MAAM,IAAI,MAAM,6EAA6E;CAE9F,OAAO;EACN,MAAM;EACN,gBAAgB,SAAS,KAAK,WAAW,YAAY;EACrD,OAAO,OAAO,SAAS,YACtB,MAAM,MAAM,SAAS,EACpB,SAAS,EACR,WAAW;GAAE,WAAW,QAAQ,IAAI;GAAW,QAAQ,QAAQ,IAAI;EAAO,EAC3E,EACD,CAAC;CACH;AACD"}
1
+ {"version":3,"file":"tanstack-start.js","names":[],"sources":["../src/tanstack-start/index.ts"],"sourcesContent":["import type { AnyRouter, RegisteredRouter } from \"@tanstack/react-router\";\nimport type { TrailingSlash } from \"../core/plugins/trailing-slash.js\";\nimport { requestContextValues } from \"../core/request-context.js\";\nimport type { FrameworkRuntime, Mode } from \"../core/types.js\";\n\n/**\n * The `trailingSlash` mode of a TanStack router: the app's registered router\n * by default. A router with no `trailingSlash` has the mode `never`. With no\n * registered router, it is every mode.\n *\n * Use it with `satisfies` on the server's mode. TypeScript then fails when the\n * two modes differ, because different modes make the redirects loop.\n *\n * @example\n * createServer({ plugins: defaultPlugins({ trailingSlash: \"never\" satisfies RouterTrailingSlash }) });\n */\nexport type RouterTrailingSlash<TRouter extends AnyRouter = RegisteredRouter> = ModeOf<\n\tTRouter[\"options\"][\"trailingSlash\"]\n>;\n\n/** A router's `trailingSlash` type as a mode. Why the `any` test: `AnyRouter` has an `any` mode, and a conditional type makes `never` of it. */\ntype ModeOf<TOption> = 0 extends 1 & TOption\n\t? TrailingSlash\n\t: NonNullable<TOption> extends infer TMode extends TrailingSlash\n\t\t? TMode\n\t\t: TrailingSlash;\n\n/** The prefix of Start's server functions when the config sets none. */\nconst DEFAULT_SERVER_FN_BASE = \"/_serverFn/\";\n\n/** The part of a TanStack Start server entry that the adapter calls. */\ntype StartServerEntry = {\n\tfetch: (\n\t\trequest: Request,\n\t\toptions?: { context?: Record<string, unknown> },\n\t) => Response | Promise<Response>;\n};\n\n/** Whether a module's default export is a TanStack Start server entry. */\nfunction startServerEntry(module: unknown): StartServerEntry | undefined {\n\tif (typeof module !== \"object\" || module == null) {\n\t\treturn undefined;\n\t}\n\tconst entry: unknown = Reflect.get(module, \"default\");\n\tif (typeof entry !== \"object\" || entry == null || !(\"fetch\" in entry)) {\n\t\treturn undefined;\n\t}\n\tconst { fetch } = entry;\n\tif (typeof fetch !== \"function\") {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tfetch: async (request, options) => {\n\t\t\tconst response: unknown = await Reflect.apply(fetch, entry, [request, options]);\n\t\t\tif (!(response instanceof Response)) {\n\t\t\t\tthrow new TypeError(\"The TanStack Start server entry did not return a Response.\");\n\t\t\t}\n\t\t\treturn response;\n\t\t},\n\t};\n}\n\n/**\n * The run side of the TanStack Start adapter, for the module of Start's\n * server entry. Start gets the `requestContext()` values as `appServer` in its\n * request context. The server reads the prerendered paths that the Vite plugin\n * recorded.\n *\n * @param info.serverFnBase - The prefix of Start's server functions, `TSS_SERVER_FN_BASE`. The entry that the Vite plugin generates sets it.\n *\n * @example\n * const framework = runtime(await import(\"virtual:tanstack-start-server-entry\"), { mode: \"production\" });\n */\nexport function runtime(\n\tserverModule: unknown,\n\t{ serverFnBase = DEFAULT_SERVER_FN_BASE }: { mode: Mode; serverFnBase?: string },\n): FrameworkRuntime {\n\tconst entry = startServerEntry(serverModule);\n\tif (entry == null) {\n\t\tthrow new Error(\"The server module has no TanStack Start server entry as its default export.\");\n\t}\n\treturn {\n\t\tname: \"tanstack-start\",\n\t\tisDataRequest: (path) => path.startsWith(serverFnBase),\n\t\tfetch: async (request, context) =>\n\t\t\tentry.fetch(request, {\n\t\t\t\tcontext: {\n\t\t\t\t\tappServer: requestContextValues(context),\n\t\t\t\t},\n\t\t\t}),\n\t};\n}\n"],"mappings":";;;;AA4BA,MAAM,yBAAyB;;AAW/B,SAAS,iBAAiB,QAA+C;CACxE,IAAI,OAAO,WAAW,YAAY,UAAU,MAC3C;CAED,MAAM,QAAiB,QAAQ,IAAI,QAAQ,SAAS;CACpD,IAAI,OAAO,UAAU,YAAY,SAAS,QAAQ,EAAE,WAAW,QAC9D;CAED,MAAM,EAAE,UAAU;CAClB,IAAI,OAAO,UAAU,YACpB;CAED,OAAO,EACN,OAAO,OAAO,SAAS,YAAY;EAClC,MAAM,WAAoB,MAAM,QAAQ,MAAM,OAAO,OAAO,CAAC,SAAS,OAAO,CAAC;EAC9E,IAAI,EAAE,oBAAoB,WACzB,MAAM,IAAI,UAAU,4DAA4D;EAEjF,OAAO;CACR,EACD;AACD;;;;;;;;;;;;AAaA,SAAgB,QACf,cACA,EAAE,eAAe,0BACE;CACnB,MAAM,QAAQ,iBAAiB,YAAY;CAC3C,IAAI,SAAS,MACZ,MAAM,IAAI,MAAM,6EAA6E;CAE9F,OAAO;EACN,MAAM;EACN,gBAAgB,SAAS,KAAK,WAAW,YAAY;EACrD,OAAO,OAAO,SAAS,YACtB,MAAM,MAAM,SAAS,EACpB,SAAS,EACR,WAAW,qBAAqB,OAAO,EACxC,EACD,CAAC;CACH;AACD"}
@@ -24,18 +24,19 @@ function parsePort(value) {
24
24
  function tcp({ port, host, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS } = {}) {
25
25
  return {
26
26
  name: "tcp",
27
- start: async (fetch) => {
27
+ start: async (fetch, { trustForwardedProto = false } = {}) => {
28
28
  const options = {
29
29
  port: port ?? (process.env.PORT == null ? 3e3 : parsePort(process.env.PORT)),
30
30
  hostname: host ?? (process.env.HOST || void 0),
31
- idleTimeoutMs
31
+ idleTimeoutMs,
32
+ trustForwardedProto
32
33
  };
33
34
  if ("Bun" in globalThis) return (await import("./bun-BCz6K_Xv.js")).listen(fetch, options);
34
- if ("Deno" in globalThis) return (await import("./deno-DNRgzHrk.js")).listen(fetch, options);
35
- return (await import("./node-ZMowKZDB.js")).listen(fetch, options);
35
+ if ("Deno" in globalThis) return (await import("./deno-aqhikNMG.js")).listen(fetch, options);
36
+ return (await import("./node-tBVQPjQv.js")).listen(fetch, options);
36
37
  }
37
38
  };
38
39
  }
39
40
 
40
41
  export { tcp as n, parsePort as t };
41
- //# sourceMappingURL=tcp-C-9AmFuM.js.map
42
+ //# sourceMappingURL=tcp-Dd1Mt6sN.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tcp-C-9AmFuM.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) => {\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};\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,UAAU;GACvB,MAAM,UAAU;IACf,MAAM,SAAS,QAAQ,IAAI,QAAQ,OAAO,MAAO,UAAU,QAAQ,IAAI,IAAI;IAC3E,UAAU,SAAS,QAAQ,IAAI,QAAQ;IACvC;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"}
1
+ {"version":3,"file":"tcp-Dd1Mt6sN.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"}
@@ -0,0 +1,36 @@
1
+ import { g as Plugin } from "./types-DLYxYS6M.js";
2
+ /**
3
+ * How a page URL ends:
4
+ *
5
+ * - `never`: with no trailing slash, such as `/docs/button`.
6
+ * - `always`: with a trailing slash, such as `/docs/button/`.
7
+ * - `preserve`: as the request has it. The server sends no redirect.
8
+ */
9
+ type TrailingSlash = "never" | "always" | "preserve";
10
+ /** Options for {@link trailingSlash}. */
11
+ type TrailingSlashOptions = {
12
+ mode: TrailingSlash;
13
+ };
14
+ /**
15
+ * Sends a 308 from a page URL to the same URL in `mode`, so each page has one
16
+ * URL. It applies to rendered and prerendered pages, because the server cannot
17
+ * tell which paths have a route. The redirect keeps the query string.
18
+ *
19
+ * It sends no redirect for `/`, a method other than GET or HEAD, a data
20
+ * request of the framework, a path that one of the app's own Hono routes
21
+ * matches, such as `app.get("/livez")`, or a path that already has the
22
+ * mode's form. `always` adds no slash to a file in the client build, such as
23
+ * `/LICENSE`, or to a path whose last segment has a dot, such as `/llms.txt`.
24
+ *
25
+ * Set the same mode in the framework's router when it has one. Else the two
26
+ * redirects loop: the server sends `/x` to `/x/`, and the router sends `/x/`
27
+ * back to `/x`. For TanStack Start, check the mode against the router with
28
+ * `RouterTrailingSlash` from `@ngrok/app-server/tanstack-start`. React Router
29
+ * has no trailing-slash option, so it answers both forms itself.
30
+ *
31
+ * @example
32
+ * createServer({ plugins: defaultPlugins({ trailingSlash: "always" }) });
33
+ */
34
+ declare function trailingSlash({ mode }: TrailingSlashOptions): Plugin;
35
+ export { TrailingSlashOptions as n, trailingSlash as r, TrailingSlash as t };
36
+ //# sourceMappingURL=trailing-slash-DX7NB88H.d.ts.map