@ngrok/app-server 0.4.1 → 0.5.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 (119) hide show
  1. package/README.md +223 -64
  2. package/dist/brotli-only-BVAagKt3.js +63 -0
  3. package/dist/build-id-CwMbED1n.js +245 -0
  4. package/dist/{build-manifest-DBMWe3Lx.js → build-manifest-CoBztw_6.js} +13 -4
  5. package/dist/bun-BCz6K_Xv.js +1 -2
  6. package/dist/check-count-DQl5z_qe.js +17 -0
  7. package/dist/cli.js +9 -6
  8. package/dist/client-browser.d.ts +2 -3
  9. package/dist/client-browser.js +1 -1
  10. package/dist/client.d.ts +5 -4
  11. package/dist/client.js +9 -6
  12. package/dist/{compress-Cp5NfXCC.js → compress-2w3jqBh7.js} +2 -3
  13. package/dist/{compression-CT2mWlKM.js → compression-uJxu0JVb.js} +32 -5
  14. package/dist/content-types-Le-5BNEC.js +10 -0
  15. package/dist/{create-server-Bp1yILQk.js → create-server-DVTZun6D.js} +617 -306
  16. package/dist/create-server-PA0qniaK.js +3 -0
  17. package/dist/{create-server-X2GR-U6t.d.ts → create-server-UVsHFQyK.d.ts} +116 -54
  18. package/dist/deno-aqhikNMG.js +1 -2
  19. package/dist/{entry-BoxCqc6w.js → entry-CMhX3yf8.js} +85 -65
  20. package/dist/entry-CvZ4U0ia.js +3 -0
  21. package/dist/{entry-DZTCaL3d.d.ts → entry-DBq_3s8X.d.ts} +10 -36
  22. package/dist/entry-protocol-C30UPXzy.js +14 -0
  23. package/dist/entry-source-DSE5NAJu.js +70 -0
  24. package/dist/entry-source-SHoE-DUP.js +3 -0
  25. package/dist/exit-Hh-O3gp4.js +83 -0
  26. package/dist/{header-hook-Vzw9J9BY.js → header-hook-JfqaTt34.js} +69 -23
  27. package/dist/{index-B8LsM6Mh.d.ts → index-gzGs53Ue.d.ts} +43 -38
  28. package/dist/index.d.ts +88 -44
  29. package/dist/index.js +216 -84
  30. package/dist/listen-options-7TaXjyrk.js +1 -2
  31. package/dist/{load-entry-CCPWbsrj.js → load-entry-Bgq1_HDV.js} +11 -12
  32. package/dist/{log-DQAS5gGT.js → log-DfC9D5_T.js} +70 -49
  33. package/dist/{node-D6m6e6EI.js → node-DQPrMFyc.js} +20 -8
  34. package/dist/node-DyKDFII0.js +263 -0
  35. package/dist/node-vite.d.ts +2 -3
  36. package/dist/node-vite.js +1 -1
  37. package/dist/node.d.ts +41 -64
  38. package/dist/node.js +3 -3
  39. package/dist/react-router-vite.d.ts +2 -3
  40. package/dist/react-router-vite.js +1 -1
  41. package/dist/react-router.d.ts +6 -17
  42. package/dist/react-router.js +9 -14
  43. package/dist/request-context-Cslbrscf.js +163 -0
  44. package/dist/{response-edge-CU8ZvL_F.js → response-edge-Ow5Pi5qF.js} +13 -10
  45. package/dist/{response-writer-D7KHfr8n.js → response-writer-Dd4Ey99f.js} +57 -21
  46. package/dist/{script-hashes-CU7P9oZU.js → script-hashes-BdvJ0QI_.js} +2 -3
  47. package/dist/serve-AatMo9k6.js +26 -0
  48. package/dist/{stale-build-navigation-rg5xxmTr.js → stale-build-navigation-Qf_Lem39.js} +4 -5
  49. package/dist/{stale-build-navigation-ypV7Ow4o.d.ts → stale-build-navigation-WjhD8zHi.d.ts} +4 -4
  50. package/dist/start-DYFyGKsM.js +470 -0
  51. package/dist/static-files-BdTPam5b.js +438 -0
  52. package/dist/static-pages-6IBHdYQc.d.ts +30 -0
  53. package/dist/tanstack-start-vite.d.ts +2 -3
  54. package/dist/tanstack-start-vite.js +1 -1
  55. package/dist/tanstack-start.d.ts +3 -4
  56. package/dist/tanstack-start.js +2 -3
  57. package/dist/tcp-3v4pmnYU.js +58 -0
  58. package/dist/testing.d.ts +8 -6
  59. package/dist/testing.js +19 -17
  60. package/dist/{trailing-slash-D2QWKWEu.d.ts → trailing-slash-C-yBKCib.d.ts} +2 -3
  61. package/dist/{types-MgFtkNQW.d.ts → types-KsKRDwAv.d.ts} +97 -46
  62. package/dist/vercel-pages.d.ts +3 -16
  63. package/dist/vercel-pages.js +1 -2
  64. package/dist/vercel-vite.d.ts +4 -5
  65. package/dist/vercel-vite.js +48 -44
  66. package/dist/vercel.d.ts +13 -10
  67. package/dist/vercel.js +48 -35
  68. package/dist/{vite-D4hfj3ph.js → vite-Brb8YR9I.js} +2 -7
  69. package/dist/{vite-B-GfswoH.js → vite-CHppJWp_.js} +5 -7
  70. package/dist/{vite-DyrhyKEr.js → vite-DjlHdyTM.js} +2 -7
  71. package/dist/vite.d.ts +2 -2
  72. package/dist/vite.js +885 -2
  73. package/package.json +13 -12
  74. package/dist/brotli-only-DrA29Ecw.js +0 -97
  75. package/dist/brotli-only-DrA29Ecw.js.map +0 -1
  76. package/dist/build-id-B0448vZH.js +0 -151
  77. package/dist/build-id-B0448vZH.js.map +0 -1
  78. package/dist/build-manifest-DBMWe3Lx.js.map +0 -1
  79. package/dist/bun-BCz6K_Xv.js.map +0 -1
  80. package/dist/cli.js.map +0 -1
  81. package/dist/client.js.map +0 -1
  82. package/dist/compress-Cp5NfXCC.js.map +0 -1
  83. package/dist/compression-CT2mWlKM.js.map +0 -1
  84. package/dist/create-server-Bp1yILQk.js.map +0 -1
  85. package/dist/deno-aqhikNMG.js.map +0 -1
  86. package/dist/entry-BoxCqc6w.js.map +0 -1
  87. package/dist/header-hook-Vzw9J9BY.js.map +0 -1
  88. package/dist/index.js.map +0 -1
  89. package/dist/listen-options-7TaXjyrk.js.map +0 -1
  90. package/dist/load-entry-CCPWbsrj.js.map +0 -1
  91. package/dist/log-DQAS5gGT.js.map +0 -1
  92. package/dist/node-CVVdk2N6.js +0 -334
  93. package/dist/node-CVVdk2N6.js.map +0 -1
  94. package/dist/node-D6m6e6EI.js.map +0 -1
  95. package/dist/react-router.js.map +0 -1
  96. package/dist/request-context-Bxdbk5P1.js +0 -80
  97. package/dist/request-context-Bxdbk5P1.js.map +0 -1
  98. package/dist/response-edge-CU8ZvL_F.js.map +0 -1
  99. package/dist/response-writer-D7KHfr8n.js.map +0 -1
  100. package/dist/script-hashes-CU7P9oZU.js.map +0 -1
  101. package/dist/serve-W4WacdOw.js +0 -29
  102. package/dist/serve-W4WacdOw.js.map +0 -1
  103. package/dist/stale-build-navigation-rg5xxmTr.js.map +0 -1
  104. package/dist/start-j0VlxeiI.js +0 -324
  105. package/dist/start-j0VlxeiI.js.map +0 -1
  106. package/dist/static-files-C2ea8KQ6.js +0 -310
  107. package/dist/static-files-C2ea8KQ6.js.map +0 -1
  108. package/dist/tanstack-start.js.map +0 -1
  109. package/dist/tcp-BgDXbjOG.js +0 -42
  110. package/dist/tcp-BgDXbjOG.js.map +0 -1
  111. package/dist/testing.js.map +0 -1
  112. package/dist/vercel-pages.js.map +0 -1
  113. package/dist/vercel-vite.js.map +0 -1
  114. package/dist/vercel.js.map +0 -1
  115. package/dist/vite-B-GfswoH.js.map +0 -1
  116. package/dist/vite-D4hfj3ph.js.map +0 -1
  117. package/dist/vite-DPiSKHDn.js +0 -870
  118. package/dist/vite-DPiSKHDn.js.map +0 -1
  119. package/dist/vite-DyrhyKEr.js.map +0 -1
package/dist/vercel.js CHANGED
@@ -1,37 +1,43 @@
1
- import { n as flushLogs } from "./log-DQAS5gGT.js";
2
- import { i as withForwardedProto } from "./create-server-Bp1yILQk.js";
3
- import { t as host$1 } from "./node-CVVdk2N6.js";
4
- import { t as requestListener } from "./response-writer-D7KHfr8n.js";
5
- import { n as brotliOnlyFiles } from "./brotli-only-DrA29Ecw.js";
1
+ import { i as withForwardedProto } from "./create-server-DVTZun6D.js";
2
+ import { n as listedFiles, r as nodeFiles, t as host$1 } from "./node-DyKDFII0.js";
3
+ import { t as requestListener } from "./response-writer-Dd4Ey99f.js";
4
+ import { n as flushLogs, r as logWriter } from "./exit-Hh-O3gp4.js";
5
+ import { n as brotliOnlyOpen, t as FILE_LIST } from "./brotli-only-BVAagKt3.js";
6
6
 
7
7
  // src/vercel/index.ts
8
8
  /**
9
- * `files` that give each file and directory the modification time
10
- * `mtimeMs`. Why: the deploy gives each file of the function one fixed time,
11
- * so a file that changes and keeps its size would keep its ETag. `vercel()`
12
- * sets `APP_SERVER_BUILT_AT` to the time of the build.
9
+ * The files that {@link FILE_LIST} names in the client build `disk`, with no
10
+ * other read of the file system: each file with the size from the list and
11
+ * the time of the build, and each directory above a file. Gives `undefined`
12
+ * for a client build with no list.
13
13
  */
14
- function withModifiedTime(files, mtimeMs) {
15
- const { snapshot } = files;
16
- return {
17
- stat: async (path) => {
18
- const info = await files.stat(path);
19
- return info == null ? void 0 : {
20
- ...info,
21
- mtimeMs
22
- };
23
- },
24
- open: files.open,
25
- ...snapshot == null ? {} : { snapshot: async () => withModifiedTime(await snapshot(), mtimeMs) }
26
- };
14
+ async function listedBuild(disk) {
15
+ if ((await disk.stat("/.app-server-files.json"))?.kind !== "file") return;
16
+ const text = await new Response(await disk.open(FILE_LIST)).text();
17
+ const { builtAt, files, brotliOnly } = JSON.parse(text);
18
+ const entries = /* @__PURE__ */ new Map();
19
+ const directory = { kind: "directory" };
20
+ for (const sizes of [files, brotliOnly]) for (const [path, size] of Object.entries(sizes)) {
21
+ entries.set(path, {
22
+ kind: "file",
23
+ size,
24
+ mtimeMs: builtAt
25
+ });
26
+ for (let parent = path.slice(0, path.lastIndexOf("/")) || "/"; !entries.has(parent); parent = parent.slice(0, parent.lastIndexOf("/")) || "/") entries.set(parent, directory);
27
+ }
28
+ return listedFiles(entries, brotliOnlyOpen(disk.open, new Set(Object.keys(brotliOnly))));
27
29
  }
28
30
  /**
29
- * The vercel host: one Vercel Function on Node.js. It reads the client build
30
- * from the function's files and keeps `requestContext()` in
31
- * `AsyncLocalStorage`, as the node host does. It has no listeners and no
32
- * lifecycle: Vercel starts and stops the function, and {@link handler} calls
33
- * the entry's `fetch`. It reads a file that the function keeps only as a
34
- * brotli copy through that copy (see `vercel()`).
31
+ * The vercel host: one Vercel Function on Node.js. It keeps
32
+ * `requestContext()` in `AsyncLocalStorage`, as the node host does. It has no
33
+ * listeners and no lifecycle: Vercel starts and stops the function, and
34
+ * {@link handler} calls the entry's `fetch`.
35
+ *
36
+ * It serves the files of the client build that the list of `vercel()` names
37
+ * ({@link FILE_LIST}), so a cold start reads one file, not each directory. It
38
+ * reads a file that the function keeps only as a brotli copy through that
39
+ * copy. A client build with no list, such as in development, comes from the
40
+ * file system, as on the node host.
35
41
  *
36
42
  * Why no gzip: Vercel's CDN compresses each response, with Brotli when the
37
43
  * client accepts it.
@@ -40,13 +46,21 @@ function withModifiedTime(files, mtimeMs) {
40
46
  * export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
41
47
  */
42
48
  const host = {
43
- name: "vercel",
44
49
  files: (clientDirectory) => {
45
- const files = brotliOnlyFiles(host$1.files(clientDirectory));
46
- const builtAt = Number(process.env.APP_SERVER_BUILT_AT);
47
- return Number.isFinite(builtAt) ? withModifiedTime(files, builtAt) : files;
50
+ const disk = nodeFiles(clientDirectory);
51
+ let listed;
52
+ const list = async () => {
53
+ listed ??= listedBuild(disk);
54
+ return listed;
55
+ };
56
+ return {
57
+ stat: async (path) => (await list() ?? disk).stat(path),
58
+ open: async (path, options) => (await list() ?? disk).open(path, options),
59
+ snapshot: async () => await list() ?? await disk.snapshot?.() ?? disk
60
+ };
48
61
  },
49
- ...host$1.storage == null ? {} : { storage: host$1.storage }
62
+ ...host$1.storage == null ? {} : { storage: host$1.storage },
63
+ logWriter
50
64
  };
51
65
  /**
52
66
  * The function handler for the entry of a server build. The function file
@@ -87,5 +101,4 @@ function handler(entry) {
87
101
  };
88
102
  }
89
103
 
90
- export { handler, host };
91
- //# sourceMappingURL=vercel.js.map
104
+ export { handler, host };
@@ -8,12 +8,7 @@
8
8
  * appServer({ host: node() });
9
9
  */
10
10
  function node() {
11
- return {
12
- name: "node",
13
- runtimeModule: "@ngrok/app-server/node",
14
- entryFileName: "app-server.js"
15
- };
11
+ return { runtimeModule: "@ngrok/app-server/node" };
16
12
  }
17
13
 
18
- export { node as t };
19
- //# sourceMappingURL=vite-D4hfj3ph.js.map
14
+ export { node as t };
@@ -1,3 +1,5 @@
1
+ import { t as CONTENT_TYPES } from "./content-types-Le-5BNEC.js";
2
+
1
3
  // src/react-router/vite.ts
2
4
  /**
3
5
  * The build side of the React Router adapter. `appServer` uses it when the
@@ -8,15 +10,11 @@
8
10
  */
9
11
  function reactRouterAdapter() {
10
12
  return {
11
- name: "react-router",
12
13
  serverModule: "virtual:react-router/server-build",
13
14
  runtimeModule: "@ngrok/app-server/react-router",
14
- isPrerenderPass: () => process.env.IS_RR_BUILD_REQUEST === "yes",
15
- validate: (config) => {
16
- if (config.base !== "/") throw new Error(`@ngrok/app-server serves a build at "/" only, and this config has the base "${config.base}".`);
17
- }
15
+ contentTypes: CONTENT_TYPES,
16
+ isPrerenderPass: () => process.env.IS_RR_BUILD_REQUEST === "yes"
18
17
  };
19
18
  }
20
19
 
21
- export { reactRouterAdapter as t };
22
- //# sourceMappingURL=vite-B-GfswoH.js.map
20
+ export { reactRouterAdapter as t };
@@ -10,16 +10,11 @@
10
10
  */
11
11
  function tanstackStartAdapter() {
12
12
  return {
13
- name: "tanstack-start",
14
13
  serverModule: "virtual:tanstack-start-server-entry",
15
14
  runtimeModule: "@ngrok/app-server/tanstack-start",
16
15
  runtimeOptions: "{ serverFnBase: process.env.TSS_SERVER_FN_BASE }",
17
- isPrerenderPass: () => process.env.TSS_PRERENDERING === "true",
18
- validate: (config) => {
19
- if (config.base !== "/") throw new Error(`@ngrok/app-server serves a build at "/" only, and this config has the base "${config.base}".`);
20
- }
16
+ isPrerenderPass: () => process.env.TSS_PRERENDERING === "true"
21
17
  };
22
18
  }
23
19
 
24
- export { tanstackStartAdapter as t };
25
- //# sourceMappingURL=vite-DyrhyKEr.js.map
20
+ export { tanstackStartAdapter as t };
package/dist/vite.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as SERVER_ENTRY_ID, i as HostOutput, n as FrameworkBuild, o as appServer, r as HostBuild, s as serverEntrySource, t as AppServerOptions } from "./index-B8LsM6Mh.js";
2
- export { AppServerOptions, FrameworkBuild, HostBuild, HostOutput, SERVER_ENTRY_ID, appServer, serverEntrySource };
1
+ import { a as appServer, i as HostOutput, n as FrameworkBuild, r as HostBuild, t as AppServerOptions } from "./index-gzGs53Ue.js";
2
+ export { AppServerOptions, FrameworkBuild, HostBuild, HostOutput, appServer };