@ngrok/app-server 0.1.0 → 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.
Files changed (70) hide show
  1. package/README.md +77 -22
  2. package/dist/build-manifest-8NfD1wnO.js +45 -0
  3. package/dist/build-manifest-8NfD1wnO.js.map +1 -0
  4. package/dist/{bun-DCGnDEPn.js → bun-BCz6K_Xv.js} +12 -8
  5. package/dist/bun-BCz6K_Xv.js.map +1 -0
  6. package/dist/cli.js +15 -13
  7. package/dist/cli.js.map +1 -1
  8. package/dist/{deno-BnMfk2n1.js → deno-DNRgzHrk.js} +4 -4
  9. package/dist/deno-DNRgzHrk.js.map +1 -0
  10. package/dist/{entry-2XXp2Ukh.js → entry-BkdUub2S.js} +179 -334
  11. package/dist/entry-BkdUub2S.js.map +1 -0
  12. package/dist/index-oSE-tYRW.d.ts +88 -0
  13. package/dist/index.d.ts +212 -27
  14. package/dist/index.js +26 -14
  15. package/dist/index.js.map +1 -1
  16. package/dist/{listen-options-DHWmSWGi.js → listen-options-7TaXjyrk.js} +2 -2
  17. package/dist/listen-options-7TaXjyrk.js.map +1 -0
  18. package/dist/load-entry-C03qqmhr.js +33 -0
  19. package/dist/load-entry-C03qqmhr.js.map +1 -0
  20. package/dist/log-CsjaKM8U.js +59 -0
  21. package/dist/log-CsjaKM8U.js.map +1 -0
  22. package/dist/{node-79my3Uix.js → node-CG7qXuWZ.js} +4 -4
  23. package/dist/node-CG7qXuWZ.js.map +1 -0
  24. package/dist/node-YWPGmzAk.js +215 -0
  25. package/dist/node-YWPGmzAk.js.map +1 -0
  26. package/dist/node-ZMowKZDB.js +3 -0
  27. package/dist/node-vite.d.ts +10 -0
  28. package/dist/node-vite.js +18 -0
  29. package/dist/node-vite.js.map +1 -0
  30. package/dist/node.d.ts +67 -0
  31. package/dist/node.js +4 -0
  32. package/dist/react-router-vite.d.ts +9 -0
  33. package/dist/react-router-vite.js +21 -0
  34. package/dist/react-router-vite.js.map +1 -0
  35. package/dist/react-router.d.ts +11 -24
  36. package/dist/react-router.js +15 -25
  37. package/dist/react-router.js.map +1 -1
  38. package/dist/serve-Cleo8RMO.js +29 -0
  39. package/dist/serve-Cleo8RMO.js.map +1 -0
  40. package/dist/start-CINALHxy.js +230 -0
  41. package/dist/start-CINALHxy.js.map +1 -0
  42. package/dist/tanstack-start-vite.d.ts +11 -0
  43. package/dist/tanstack-start-vite.js +24 -0
  44. package/dist/tanstack-start-vite.js.map +1 -0
  45. package/dist/tanstack-start.d.ts +17 -0
  46. package/dist/tanstack-start.js +50 -0
  47. package/dist/tanstack-start.js.map +1 -0
  48. package/dist/tcp-C-9AmFuM.js +41 -0
  49. package/dist/tcp-C-9AmFuM.js.map +1 -0
  50. package/dist/types-BfCkS7kQ.d.ts +203 -0
  51. package/dist/vite-mYZ2Y69u.js +144 -0
  52. package/dist/vite-mYZ2Y69u.js.map +1 -0
  53. package/dist/vite.d.ts +2 -27
  54. package/dist/vite.js +2 -2
  55. package/package.json +28 -2
  56. package/dist/bun-DCGnDEPn.js.map +0 -1
  57. package/dist/captured-headers-ewL_t3MQ.js +0 -48
  58. package/dist/captured-headers-ewL_t3MQ.js.map +0 -1
  59. package/dist/deno-BnMfk2n1.js.map +0 -1
  60. package/dist/dev-DCytOhpM.js +0 -132
  61. package/dist/dev-DCytOhpM.js.map +0 -1
  62. package/dist/entry-2XXp2Ukh.js.map +0 -1
  63. package/dist/entry-CIpwaayZ.d.ts +0 -293
  64. package/dist/listen-options-DHWmSWGi.js.map +0 -1
  65. package/dist/node-2wWBMFeO.js +0 -3
  66. package/dist/node-79my3Uix.js.map +0 -1
  67. package/dist/start-kxw_NM4q.js +0 -16
  68. package/dist/start-kxw_NM4q.js.map +0 -1
  69. package/dist/vite-CrNqpoeK.js +0 -102
  70. package/dist/vite-CrNqpoeK.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-router-vite.js","names":[],"sources":["../src/react-router/vite.ts"],"sourcesContent":["import type { FrameworkBuild } from \"../vite/index.js\";\n\n/**\n * The build side of the React Router adapter.\n *\n * @example\n * appServer({ framework: reactRouterAdapter(), host: node(), app: \"./server.ts\" });\n */\nexport function reactRouterAdapter(): FrameworkBuild {\n\treturn {\n\t\tname: \"react-router\",\n\t\tserverModule: \"virtual:react-router/server-build\",\n\t\truntimeModule: \"@ngrok/app-server/react-router\",\n\t\t// Why this flag: React Router sets it for the preview server of its prerender pass only.\n\t\tisPrerenderPass: () => process.env.IS_RR_BUILD_REQUEST === \"yes\",\n\t\tvalidate: (config) => {\n\t\t\tif (config.base !== \"/\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@ngrok/app-server serves a build at \"/\" only, and this config has the base \"${config.base}\".`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,qBAAqC;CACpD,OAAO;EACN,MAAM;EACN,cAAc;EACd,eAAe;EAEf,uBAAuB,QAAQ,IAAI,wBAAwB;EAC3D,WAAW,WAAW;GACrB,IAAI,OAAO,SAAS,KACnB,MAAM,IAAI,MACT,+EAA+E,OAAO,KAAK,GAC5F;EAEF;CACD;AACD"}
@@ -1,23 +1,19 @@
1
- import { D as SetupInfo, T as RequestLogger, r as AppServer, t as AppServerEntry, v as FrameworkAdapter } from "./entry-CIpwaayZ.js";
1
+ import { f as Mode, i as FrameworkRuntime, m as RequestContext } from "./types-BfCkS7kQ.js";
2
2
  import { ServerBuild } from "react-router";
3
3
  /** What the server puts in React Router's context for each request. */
4
- export type AppServerContext = {
5
- /** The request ID, when the `requestId` plugin runs. */
6
- requestId: string | undefined;
7
- /** The request's logger. Its lines carry the request ID. */
8
- logger: RequestLogger;
9
- };
4
+ export type AppServerContext = RequestContext;
10
5
  /**
11
6
  * The React Router context key for {@link AppServerContext}. Outside a server
12
7
  * request, such as in React Router's prerender pass, it holds no request ID
13
- * and a logger that writes to `jsonSink()`.
8
+ * and a logger that writes to `jsonSink()`. `requestContext()` from
9
+ * `@ngrok/app-server` gives the same values.
14
10
  *
15
11
  * @example
16
12
  * export async function loader({ context }: Route.LoaderArgs) {
17
13
  * context.get(appServerContext).logger.info("loading the dashboard");
18
14
  * }
19
15
  */
20
- export declare const appServerContext: import("react-router").RouterContext<AppServerContext>;
16
+ export declare const appServerContext: import("react-router").RouterContext<RequestContext>;
21
17
  /**
22
18
  * Whether a module is a React Router server build.
23
19
  *
@@ -26,22 +22,13 @@ export declare const appServerContext: import("react-router").RouterContext<AppS
26
22
  */
27
23
  export declare function isServerBuild(value: unknown): value is ServerBuild;
28
24
  /**
29
- * The framework adapter for a React Router server build. Each request gets a
30
- * `RouterContextProvider` that holds {@link appServerContext}.
25
+ * The run side of the React Router adapter, for a server build. Each request
26
+ * gets a `RouterContextProvider` that holds {@link appServerContext}.
31
27
  *
32
28
  * @example
33
- * const framework = createAdapter(build, { mode: "production" });
29
+ * const framework = runtime(build, { mode: "production" });
34
30
  */
35
- export declare function createAdapter(build: ServerBuild, { mode }: {
36
- mode: SetupInfo["mode"];
37
- }): FrameworkAdapter;
38
- /**
39
- * The `appServer` export of a React Router server build. The `serverEntry`
40
- * Vite plugin adds it, so the copy of this package in the build runs the
41
- * server. With no `app`, the server has the default plugins.
42
- *
43
- * @example
44
- * export const appServer = appServerEntry(build, app);
45
- */
46
- export declare function appServerEntry(build: ServerBuild, app?: AppServer): AppServerEntry;
31
+ export declare function runtime(build: unknown, { mode }: {
32
+ mode: Mode;
33
+ }): FrameworkRuntime;
47
34
  //# sourceMappingURL=react-router.d.ts.map
@@ -1,12 +1,12 @@
1
- import { h as sinkLogger, m as jsonSink, r as createServer, t as createEntry } from "./entry-2XXp2Ukh.js";
2
- import { resolve } from "node:path";
1
+ import { i as sinkLogger, n as jsonSink } from "./log-CsjaKM8U.js";
3
2
  import { RouterContextProvider, createContext, createRequestHandler } from "react-router";
4
3
 
5
- // src/react-router.ts
4
+ // src/react-router/index.ts
6
5
  /**
7
6
  * The React Router context key for {@link AppServerContext}. Outside a server
8
7
  * request, such as in React Router's prerender pass, it holds no request ID
9
- * and a logger that writes to `jsonSink()`.
8
+ * and a logger that writes to `jsonSink()`. `requestContext()` from
9
+ * `@ngrok/app-server` gives the same values.
10
10
  *
11
11
  * @example
12
12
  * export async function loader({ context }: Route.LoaderArgs) {
@@ -27,19 +27,23 @@ function isServerBuild(value) {
27
27
  return typeof value === "object" && value != null && "routes" in value && "entry" in value && "assetsBuildDirectory" in value && typeof value.assetsBuildDirectory === "string";
28
28
  }
29
29
  /**
30
- * The framework adapter for a React Router server build. Each request gets a
31
- * `RouterContextProvider` that holds {@link appServerContext}.
30
+ * The run side of the React Router adapter, for a server build. Each request
31
+ * gets a `RouterContextProvider` that holds {@link appServerContext}.
32
32
  *
33
33
  * @example
34
- * const framework = createAdapter(build, { mode: "production" });
34
+ * const framework = runtime(build, { mode: "production" });
35
35
  */
36
- function createAdapter(build, { mode }) {
36
+ function runtime(build, { mode }) {
37
+ if (!isServerBuild(build)) throw new Error("The server module is not a React Router server build.");
37
38
  if (build.publicPath !== "/") throw new Error(`@ngrok/app-server serves a build at "/" only, and this build has the publicPath "${build.publicPath}".`);
38
39
  const handler = createRequestHandler(build, mode);
39
40
  return {
40
- clientDirectory: resolve(build.assetsBuildDirectory),
41
+ name: "react-router",
42
+ clientDirectory: build.assetsBuildDirectory,
41
43
  prerenderedPaths: build.prerender,
42
- fetch: (request, context) => {
44
+ isDataRequest: (path) => path.endsWith(".data"),
45
+ contentTypes: { ".data": "text/x-script" },
46
+ fetch: async (request, context) => {
43
47
  const routerContext = new RouterContextProvider();
44
48
  routerContext.set(appServerContext, {
45
49
  requestId: context.var.requestId,
@@ -49,20 +53,6 @@ function createAdapter(build, { mode }) {
49
53
  }
50
54
  };
51
55
  }
52
- /**
53
- * The `appServer` export of a React Router server build. The `serverEntry`
54
- * Vite plugin adds it, so the copy of this package in the build runs the
55
- * server. With no `app`, the server has the default plugins.
56
- *
57
- * @example
58
- * export const appServer = appServerEntry(build, app);
59
- */
60
- function appServerEntry(build, app = createServer({ trustForwardedProto: process.env.TRUST_FORWARDED_PROTO === "1" })) {
61
- return createEntry({
62
- app,
63
- framework: (mode) => createAdapter(build, { mode })
64
- });
65
- }
66
56
 
67
- export { appServerContext, appServerEntry, createAdapter, isServerBuild };
57
+ export { appServerContext, isServerBuild, runtime };
68
58
  //# sourceMappingURL=react-router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-router.js","names":[],"sources":["../src/react-router.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport {\n\t//,\n\tcreateContext,\n\tcreateRequestHandler,\n\tRouterContextProvider,\n\ttype ServerBuild,\n} from \"react-router\";\nimport { createServer, type AppServer } from \"./create-server.js\";\nimport { createEntry, type AppServerEntry } from \"./entry.js\";\nimport { jsonSink, sinkLogger } from \"./log.js\";\nimport type { FrameworkAdapter, RequestLogger, SetupInfo } from \"./types.js\";\n\n/** What the server puts in React Router's context for each request. */\nexport type AppServerContext = {\n\t/** The request ID, when the `requestId` plugin runs. */\n\trequestId: string | undefined;\n\t/** The request's logger. Its lines carry the request ID. */\n\tlogger: RequestLogger;\n};\n\n/**\n * The React Router context key for {@link AppServerContext}. Outside a server\n * request, such as in React Router's prerender pass, it holds no request ID\n * and a logger that writes to `jsonSink()`.\n *\n * @example\n * export async function loader({ context }: Route.LoaderArgs) {\n * \tcontext.get(appServerContext).logger.info(\"loading the dashboard\");\n * }\n */\nexport const appServerContext = createContext<AppServerContext>({\n\trequestId: undefined,\n\tlogger: sinkLogger(jsonSink()),\n});\n\n/**\n * Whether a module is a React Router server build.\n *\n * @example\n * isServerBuild(await import(\"./build/server/index.js\")); // => true\n */\nexport function isServerBuild(value: unknown): value is ServerBuild {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"routes\" in value &&\n\t\t\"entry\" in value &&\n\t\t\"assetsBuildDirectory\" in value &&\n\t\ttypeof value.assetsBuildDirectory === \"string\"\n\t);\n}\n\n/**\n * The framework adapter for a React Router server build. Each request gets a\n * `RouterContextProvider` that holds {@link appServerContext}.\n *\n * @example\n * const framework = createAdapter(build, { mode: \"production\" });\n */\nexport function createAdapter(\n\tbuild: ServerBuild,\n\t{ mode }: { mode: SetupInfo[\"mode\"] },\n): FrameworkAdapter {\n\tif (build.publicPath !== \"/\") {\n\t\tthrow new Error(\n\t\t\t`@ngrok/app-server serves a build at \"/\" only, and this build has the publicPath \"${build.publicPath}\".`,\n\t\t);\n\t}\n\tconst handler = createRequestHandler(build, mode);\n\treturn {\n\t\tclientDirectory: resolve(build.assetsBuildDirectory),\n\t\tprerenderedPaths: build.prerender,\n\t\tfetch: (request, context) => {\n\t\t\tconst routerContext = new RouterContextProvider();\n\t\t\trouterContext.set(appServerContext, {\n\t\t\t\trequestId: context.var.requestId,\n\t\t\t\tlogger: context.var.logger,\n\t\t\t});\n\t\t\treturn handler(request, routerContext);\n\t\t},\n\t};\n}\n\n/**\n * The `appServer` export of a React Router server build. The `serverEntry`\n * Vite plugin adds it, so the copy of this package in the build runs the\n * server. With no `app`, the server has the default plugins.\n *\n * @example\n * export const appServer = appServerEntry(build, app);\n */\nexport function appServerEntry(\n\tbuild: ServerBuild,\n\tapp: AppServer = createServer({ trustForwardedProto: process.env.TRUST_FORWARDED_PROTO === \"1\" }),\n): AppServerEntry {\n\treturn createEntry({ app, framework: (mode) => createAdapter(build, { mode }) });\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAa,mBAAmB,cAAgC;CAC/D,WAAW;CACX,QAAQ,WAAW,SAAS,CAAC;AAC9B,CAAC;;;;;;;AAQD,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,YAAY,SACZ,WAAW,SACX,0BAA0B,SAC1B,OAAO,MAAM,yBAAyB;AAExC;;;;;;;;AASA,SAAgB,cACf,OACA,EAAE,QACiB;CACnB,IAAI,MAAM,eAAe,KACxB,MAAM,IAAI,MACT,oFAAoF,MAAM,WAAW,GACtG;CAED,MAAM,UAAU,qBAAqB,OAAO,IAAI;CAChD,OAAO;EACN,iBAAiB,QAAQ,MAAM,oBAAoB;EACnD,kBAAkB,MAAM;EACxB,QAAQ,SAAS,YAAY;GAC5B,MAAM,gBAAgB,IAAI,sBAAsB;GAChD,cAAc,IAAI,kBAAkB;IACnC,WAAW,QAAQ,IAAI;IACvB,QAAQ,QAAQ,IAAI;GACrB,CAAC;GACD,OAAO,QAAQ,SAAS,aAAa;EACtC;CACD;AACD;;;;;;;;;AAUA,SAAgB,eACf,OACA,MAAiB,aAAa,EAAE,qBAAqB,QAAQ,IAAI,0BAA0B,IAAI,CAAC,GAC/E;CACjB,OAAO,YAAY;EAAE;EAAK,YAAY,SAAS,cAAc,OAAO,EAAE,KAAK,CAAC;CAAE,CAAC;AAChF"}
1
+ {"version":3,"file":"react-router.js","names":[],"sources":["../src/react-router/index.ts"],"sourcesContent":["import { createContext, createRequestHandler, RouterContextProvider } from \"react-router\";\nimport type { ServerBuild } from \"react-router\";\nimport { jsonSink, sinkLogger } from \"../core/log.js\";\nimport type { FrameworkRuntime, Mode, RequestContext } from \"../core/types.js\";\n\n/** What the server puts in React Router's context for each request. */\nexport type AppServerContext = RequestContext;\n\n/**\n * The React Router context key for {@link AppServerContext}. Outside a server\n * request, such as in React Router's prerender pass, it holds no request ID\n * and a logger that writes to `jsonSink()`. `requestContext()` from\n * `@ngrok/app-server` gives the same values.\n *\n * @example\n * export async function loader({ context }: Route.LoaderArgs) {\n * \tcontext.get(appServerContext).logger.info(\"loading the dashboard\");\n * }\n */\nexport const appServerContext = createContext<AppServerContext>({\n\trequestId: undefined,\n\tlogger: sinkLogger(jsonSink()),\n});\n\n/**\n * Whether a module is a React Router server build.\n *\n * @example\n * isServerBuild(await import(\"./build/server/index.js\")); // => true\n */\nexport function isServerBuild(value: unknown): value is ServerBuild {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue != null &&\n\t\t\"routes\" in value &&\n\t\t\"entry\" in value &&\n\t\t\"assetsBuildDirectory\" in value &&\n\t\ttypeof value.assetsBuildDirectory === \"string\"\n\t);\n}\n\n/**\n * The run side of the React Router adapter, for a server build. Each request\n * gets a `RouterContextProvider` that holds {@link appServerContext}.\n *\n * @example\n * const framework = runtime(build, { mode: \"production\" });\n */\nexport function runtime(build: unknown, { mode }: { mode: Mode }): FrameworkRuntime {\n\tif (!isServerBuild(build)) {\n\t\tthrow new Error(\"The server module is not a React Router server build.\");\n\t}\n\t// Why also here: the Vite plugin checks the base, but a plain build skips the plugin.\n\tif (build.publicPath !== \"/\") {\n\t\tthrow new Error(\n\t\t\t`@ngrok/app-server serves a build at \"/\" only, and this build has the publicPath \"${build.publicPath}\".`,\n\t\t);\n\t}\n\tconst handler = createRequestHandler(build, mode);\n\treturn {\n\t\tname: \"react-router\",\n\t\tclientDirectory: build.assetsBuildDirectory,\n\t\tprerenderedPaths: build.prerender,\n\t\tisDataRequest: (path) => path.endsWith(\".data\"),\n\t\tcontentTypes: { \".data\": \"text/x-script\" },\n\t\tfetch: async (request, context) => {\n\t\t\tconst routerContext = new RouterContextProvider();\n\t\t\trouterContext.set(appServerContext, {\n\t\t\t\trequestId: context.var.requestId,\n\t\t\t\tlogger: context.var.logger,\n\t\t\t});\n\t\t\treturn handler(request, routerContext);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,MAAa,mBAAmB,cAAgC;CAC/D,WAAW;CACX,QAAQ,WAAW,SAAS,CAAC;AAC9B,CAAC;;;;;;;AAQD,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,SAAS,QACT,YAAY,SACZ,WAAW,SACX,0BAA0B,SAC1B,OAAO,MAAM,yBAAyB;AAExC;;;;;;;;AASA,SAAgB,QAAQ,OAAgB,EAAE,QAA0C;CACnF,IAAI,CAAC,cAAc,KAAK,GACvB,MAAM,IAAI,MAAM,uDAAuD;CAGxE,IAAI,MAAM,eAAe,KACxB,MAAM,IAAI,MACT,oFAAoF,MAAM,WAAW,GACtG;CAED,MAAM,UAAU,qBAAqB,OAAO,IAAI;CAChD,OAAO;EACN,MAAM;EACN,iBAAiB,MAAM;EACvB,kBAAkB,MAAM;EACxB,gBAAgB,SAAS,KAAK,SAAS,OAAO;EAC9C,cAAc,EAAE,SAAS,gBAAgB;EACzC,OAAO,OAAO,SAAS,YAAY;GAClC,MAAM,gBAAgB,IAAI,sBAAsB;GAChD,cAAc,IAAI,kBAAkB;IACnC,WAAW,QAAQ,IAAI;IACvB,QAAQ,QAAQ,IAAI;GACrB,CAAC;GACD,OAAO,QAAQ,SAAS,aAAa;EACtC;CACD;AACD"}
@@ -0,0 +1,29 @@
1
+ import { t as loadEntry } from "./load-entry-C03qqmhr.js";
2
+ import { resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { existsSync } from "node:fs";
5
+
6
+ // src/cli/serve.ts
7
+ /**
8
+ * Where `app-server serve` looks for the server build when no path is given:
9
+ * the node host's entry in the React Router and Vite output layouts, then a
10
+ * plain React Router build.
11
+ */
12
+ const DEFAULT_BUILD_PATHS = [
13
+ "build/server/app-server.js",
14
+ "dist/server/app-server.js",
15
+ "build/server/index.js"
16
+ ];
17
+ /**
18
+ * Loads a production server build and starts it. The copy of this package in
19
+ * the build runs the server when the build has one: see `loadEntry`.
20
+ */
21
+ async function serve({ buildPath }) {
22
+ const path = buildPath ?? DEFAULT_BUILD_PATHS.find((candidate) => existsSync(candidate));
23
+ if (path == null) throw new Error(`No server build found. Build the app, or pass its path. Looked for: ${DEFAULT_BUILD_PATHS.join(", ")}.`);
24
+ const build = await import(pathToFileURL(resolve(path)).href);
25
+ await (await loadEntry(build)).start();
26
+ }
27
+
28
+ export { serve };
29
+ //# sourceMappingURL=serve-Cleo8RMO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve-Cleo8RMO.js","names":[],"sources":["../src/cli/serve.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { loadEntry } from \"./load-entry.js\";\n\n/**\n * Where `app-server serve` looks for the server build when no path is given:\n * the node host's entry in the React Router and Vite output layouts, then a\n * plain React Router build.\n */\nexport const DEFAULT_BUILD_PATHS = [\n\t\"build/server/app-server.js\",\n\t\"dist/server/app-server.js\",\n\t\"build/server/index.js\",\n];\n\n/**\n * Loads a production server build and starts it. The copy of this package in\n * the build runs the server when the build has one: see `loadEntry`.\n */\nexport async function serve({ buildPath }: { buildPath: string | undefined }): Promise<void> {\n\tconst path = buildPath ?? DEFAULT_BUILD_PATHS.find((candidate) => existsSync(candidate));\n\tif (path == null) {\n\t\tthrow new Error(\n\t\t\t`No server build found. Build the app, or pass its path. Looked for: ${DEFAULT_BUILD_PATHS.join(\", \")}.`,\n\t\t);\n\t}\n\tconst build: unknown = await import(pathToFileURL(resolve(path)).href);\n\tawait (await loadEntry(build)).start();\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,sBAAsB;CAClC;CACA;CACA;AACD;;;;;AAMA,eAAsB,MAAM,EAAE,aAA+D;CAC5F,MAAM,OAAO,aAAa,oBAAoB,MAAM,cAAc,WAAW,SAAS,CAAC;CACvF,IAAI,QAAQ,MACX,MAAM,IAAI,MACT,uEAAuE,oBAAoB,KAAK,IAAI,EAAE,EACvG;CAED,MAAM,QAAiB,MAAM,OAAO,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC;CACjE,OAAO,MAAM,UAAU,KAAK,EAAC,CAAE,MAAM;AACtC"}
@@ -0,0 +1,230 @@
1
+ import { t as parsePort } from "./tcp-C-9AmFuM.js";
2
+ import { n as jsonSink, t as errorAttributes } from "./log-CsjaKM8U.js";
3
+ import { i as exitAfterFlush, n as devServerStage } from "./node-YWPGmzAk.js";
4
+ import { t as SERVER_ENTRY_ID } from "./vite-mYZ2Y69u.js";
5
+ import { t as loadEntry } from "./load-entry-C03qqmhr.js";
6
+ import { t as listenerUrl } from "./listen-options-7TaXjyrk.js";
7
+ import { t as cancelIfClosed } from "./node-CG7qXuWZ.js";
8
+ import { IncomingMessage, ServerResponse, createServer } from "node:http";
9
+ import { getRequestListener } from "@hono/node-server";
10
+ import { createServer as createServer$1 } from "node:net";
11
+
12
+ // src/cli/served-apps.ts
13
+ /**
14
+ * Tracks the apps that `app-server start` serves. An edit to `server.ts` makes a
15
+ * new app, and the old app's plugins still hold what their `setup` opened.
16
+ * When the last request that the old app took returns, its `onShutdown` hooks
17
+ * run, and the tracker lets go of it. A route edit makes a new entry with the
18
+ * same app, which keeps its plugins.
19
+ */
20
+ function servedApps() {
21
+ let current;
22
+ const served = /* @__PURE__ */ new Set();
23
+ const retire = async (app) => {
24
+ try {
25
+ await app.entry.stopPlugins();
26
+ } finally {
27
+ served.delete(app);
28
+ }
29
+ };
30
+ return {
31
+ serve: async (entry, handle) => {
32
+ if (current?.entry.app === entry.app) current.entry = entry;
33
+ else {
34
+ if (current != null) {
35
+ current.replaced = true;
36
+ if (current.pending === 0) retire(current);
37
+ }
38
+ current = {
39
+ entry,
40
+ pending: 0,
41
+ replaced: false
42
+ };
43
+ served.add(current);
44
+ }
45
+ const app = current;
46
+ app.pending += 1;
47
+ try {
48
+ return await handle(entry);
49
+ } finally {
50
+ app.pending -= 1;
51
+ if (app.replaced && app.pending === 0) retire(app);
52
+ }
53
+ },
54
+ stopAll: async () => {
55
+ await Promise.all(Array.from(served, async (app) => {
56
+ app.entry.abortShutdownSignal();
57
+ await retire(app);
58
+ }));
59
+ }
60
+ };
61
+ }
62
+
63
+ // src/cli/start-port.ts
64
+ const MAX_PORT = 65535;
65
+ /**
66
+ * Starts `server` on `port`. When the port is in use, it tries each next port
67
+ * up to 65535, like Vite and `react-router-serve` do in development.
68
+ *
69
+ * @returns the port that the server listens on
70
+ */
71
+ async function listenFromPort(server, { port, hostname, strictPort, onPortInUse, onWildcardInUse }) {
72
+ if (port === 0) {
73
+ await bind(server, port, hostname);
74
+ return boundPort(server, port);
75
+ }
76
+ if (strictPort) {
77
+ const freeOnWildcard = hostname == null || await isFreeOnWildcard(port);
78
+ await bind(server, port, hostname);
79
+ if (!freeOnWildcard) onWildcardInUse?.(port);
80
+ return port;
81
+ }
82
+ for (let candidate = port; candidate <= MAX_PORT; candidate++) {
83
+ if (hostname == null || await isFreeOnWildcard(candidate)) try {
84
+ await bind(server, candidate, hostname);
85
+ return candidate;
86
+ } catch (error) {
87
+ if (!isAddressInUse(error)) throw error;
88
+ }
89
+ onPortInUse?.(candidate);
90
+ }
91
+ throw new Error(`No open port from ${port} to ${MAX_PORT}.`);
92
+ }
93
+ async function bind(server, port, hostname) {
94
+ return new Promise((resolve, reject) => {
95
+ function onError(error) {
96
+ server.off("listening", onListening);
97
+ reject(error);
98
+ }
99
+ function onListening() {
100
+ server.off("error", onError);
101
+ resolve();
102
+ }
103
+ server.once("error", onError);
104
+ server.once("listening", onListening);
105
+ server.listen(port, hostname);
106
+ });
107
+ }
108
+ async function isFreeOnWildcard(port) {
109
+ const probe = createServer$1();
110
+ try {
111
+ await bind(probe, port, void 0);
112
+ } catch (error) {
113
+ if (isAddressInUse(error)) return false;
114
+ throw error;
115
+ }
116
+ await new Promise((resolve) => {
117
+ probe.close(() => {
118
+ resolve();
119
+ });
120
+ });
121
+ return true;
122
+ }
123
+ function boundPort(server, fallback) {
124
+ const address = server.address();
125
+ return typeof address === "object" && address != null ? address.port : fallback;
126
+ }
127
+ function isAddressInUse(error) {
128
+ return error instanceof Error && "code" in error && error.code === "EADDRINUSE";
129
+ }
130
+
131
+ // src/cli/start.ts
132
+ /**
133
+ * Runs the app in development: the same pipeline as production, with Vite in
134
+ * middleware mode inside it. Each request loads the server entry through
135
+ * Vite's SSR runner, so an edit to a route or to the app's `server.ts` applies
136
+ * at once. HMR shares the port.
137
+ *
138
+ * The port is `--port`, else `PORT`, else Vite's `server.port`. When that port is in use, the
139
+ * server tries each next port, unless Vite's `server.strictPort` is true. The
140
+ * host is `HOST`, else Vite's `server.host`.
141
+ */
142
+ async function start() {
143
+ const vite = await import("vite");
144
+ const httpServer = createServer();
145
+ const viteServer = await vite.createServer({
146
+ server: {
147
+ middlewareMode: true,
148
+ ws: { server: httpServer }
149
+ },
150
+ appType: "custom"
151
+ });
152
+ const ssrRunner = () => {
153
+ const { ssr } = viteServer.environments;
154
+ if (ssr == null || !vite.isRunnableDevEnvironment(ssr)) throw new Error("Vite's SSR environment cannot run modules.");
155
+ return ssr.runner;
156
+ };
157
+ ssrRunner();
158
+ if (!viteServer.config.plugins.some((plugin) => plugin.name === "@ngrok/app-server")) {
159
+ await viteServer.close();
160
+ throw new Error("`app-server start` needs the `appServer` plugin from @ngrok/app-server/vite in the Vite config.");
161
+ }
162
+ const devServer = devServerStage(viteServer.middlewares);
163
+ const sink = jsonSink();
164
+ const apps = servedApps();
165
+ const listener = getRequestListener(async (request, { incoming, outgoing }) => {
166
+ try {
167
+ const response = await apps.serve(await loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)), async (entry) => entry.fetchDev(request, {
168
+ remoteAddress: incoming.socket.remoteAddress,
169
+ ...incoming instanceof IncomingMessage && outgoing instanceof ServerResponse ? {
170
+ incoming,
171
+ outgoing
172
+ } : {}
173
+ }, devServer));
174
+ return await cancelIfClosed(response, outgoing);
175
+ } catch (error) {
176
+ if (error instanceof Error) viteServer.ssrFixStacktrace(error);
177
+ sink.log("error", "dev request failed", errorAttributes(error));
178
+ return new Response(error instanceof Error ? error.stack ?? error.message : String(error), {
179
+ status: 500,
180
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
181
+ });
182
+ }
183
+ });
184
+ httpServer.on("request", (request, response) => {
185
+ listener(request, response);
186
+ });
187
+ const port = process.env.PORT == null ? viteServer.config.server.port : parsePort(process.env.PORT);
188
+ const hostname = process.env.HOST || viteHostname(viteServer.config.server.host);
189
+ const boundPort = await listenFromPort(httpServer, {
190
+ port,
191
+ hostname,
192
+ strictPort: viteServer.config.server.strictPort,
193
+ onPortInUse: (inUse) => {
194
+ sink.log("info", "port in use, trying the next port", { "server.port": inUse });
195
+ },
196
+ onWildcardInUse: (inUse) => {
197
+ sink.log("warn", "port in use on a wildcard address", {
198
+ "server.port": inUse,
199
+ "server.address": hostname
200
+ });
201
+ }
202
+ });
203
+ sink.log("info", "listening", { "app_server.urls": [listenerUrl(hostname, boundPort)] });
204
+ for (const signal of ["SIGTERM", "SIGINT"]) process.once(signal, () => {
205
+ const pluginsStopped = apps.stopAll();
206
+ httpServer.closeAllConnections();
207
+ const httpClosed = new Promise((resolve) => {
208
+ httpServer.close(() => {
209
+ resolve();
210
+ });
211
+ });
212
+ const viteClosed = viteServer.close().catch((error) => {
213
+ sink.log("error", "Vite close failed", errorAttributes(error));
214
+ process.exitCode = 1;
215
+ });
216
+ Promise.all([
217
+ pluginsStopped,
218
+ httpClosed,
219
+ viteClosed
220
+ ]).finally(exitAfterFlush);
221
+ });
222
+ }
223
+ /** The hostname for Vite's `server.host`: `true` is every interface, and no value is `localhost`. */
224
+ function viteHostname(host) {
225
+ if (host === true) return;
226
+ return typeof host === "string" && host !== "" ? host : "localhost";
227
+ }
228
+
229
+ export { start };
230
+ //# sourceMappingURL=start-CINALHxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-CINALHxy.js","names":["createServer","createHttpServer"],"sources":["../src/cli/served-apps.ts","../src/cli/start-port.ts","../src/cli/start.ts"],"sourcesContent":["import type { AppServerEntry } from \"../core/entry.js\";\n\ntype ServedApp = { entry: AppServerEntry; pending: number; replaced: boolean };\n\n/** What {@link servedApps} returns. */\ntype ServedApps = {\n\t/** Runs `handle` for a request that `entry` serves. */\n\tserve: <Result>(\n\t\tentry: AppServerEntry,\n\t\thandle: (entry: AppServerEntry) => Promise<Result>,\n\t) => Promise<Result>;\n\t/**\n\t * At exit: aborts `shutdownSignal()` and runs the `onShutdown` hooks of each\n\t * app still held. Resolves when the hooks finish or pass the deadline.\n\t */\n\tstopAll: () => Promise<void>;\n};\n\n/**\n * Tracks the apps that `app-server start` serves. An edit to `server.ts` makes a\n * new app, and the old app's plugins still hold what their `setup` opened.\n * When the last request that the old app took returns, its `onShutdown` hooks\n * run, and the tracker lets go of it. A route edit makes a new entry with the\n * same app, which keeps its plugins.\n */\nexport function servedApps(): ServedApps {\n\tlet current: ServedApp | undefined;\n\tconst served = new Set<ServedApp>();\n\t// Why keep the app until its hooks settle: `stopAll` must wait for hooks that already run.\n\t// `stopPlugins` runs the hooks once, so a second call only waits.\n\tconst retire = async (app: ServedApp) => {\n\t\ttry {\n\t\t\tawait app.entry.stopPlugins();\n\t\t} finally {\n\t\t\tserved.delete(app);\n\t\t}\n\t};\n\treturn {\n\t\tserve: async (entry, handle) => {\n\t\t\tif (current?.entry.app === entry.app) {\n\t\t\t\tcurrent.entry = entry;\n\t\t\t} else {\n\t\t\t\tif (current != null) {\n\t\t\t\t\tcurrent.replaced = true;\n\t\t\t\t\tif (current.pending === 0) {\n\t\t\t\t\t\tvoid retire(current);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcurrent = { entry, pending: 0, replaced: false };\n\t\t\t\tserved.add(current);\n\t\t\t}\n\t\t\tconst app = current;\n\t\t\tapp.pending += 1;\n\t\t\ttry {\n\t\t\t\treturn await handle(entry);\n\t\t\t} finally {\n\t\t\t\tapp.pending -= 1;\n\t\t\t\tif (app.replaced && app.pending === 0) {\n\t\t\t\t\tvoid retire(app);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tstopAll: async () => {\n\t\t\tawait Promise.all(\n\t\t\t\tArray.from(served, async (app) => {\n\t\t\t\t\tapp.entry.abortShutdownSignal();\n\t\t\t\t\tawait retire(app);\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t};\n}\n","import { createServer } from \"node:net\";\nimport type { Server } from \"node:net\";\n\nconst MAX_PORT = 65_535;\n\n/** Options for {@link listenFromPort}. */\nexport type ListenFromPortOptions = {\n\t/** The first port to try. 0 lets the OS pick one. */\n\tport: number;\n\t/** @default every interface */\n\thostname?: string | undefined;\n\t/** When true, a port in use throws and no other port is tried. */\n\tstrictPort: boolean;\n\t/** Runs for each port in use before the next port is tried. */\n\tonPortInUse?: (port: number) => void;\n\t/**\n\t * Runs when `strictPort` is true and the server listens on `hostname`, but\n\t * another server holds the port on a wildcard address.\n\t */\n\tonWildcardInUse?: (port: number) => void;\n};\n\n/**\n * Starts `server` on `port`. When the port is in use, it tries each next port\n * up to 65535, like Vite and `react-router-serve` do in development.\n *\n * @returns the port that the server listens on\n */\nexport async function listenFromPort(\n\tserver: Server,\n\t{ port, hostname, strictPort, onPortInUse, onWildcardInUse }: ListenFromPortOptions,\n): Promise<number> {\n\tif (port === 0) {\n\t\tawait bind(server, port, hostname);\n\t\treturn boundPort(server, port);\n\t}\n\tif (strictPort) {\n\t\t// Why a warning and not an error: a server on one other address also fails the wildcard\n\t\t// check, and that server does not share `hostname`. Vite warns for the same reason.\n\t\tconst freeOnWildcard = hostname == null || (await isFreeOnWildcard(port));\n\t\tawait bind(server, port, hostname);\n\t\tif (!freeOnWildcard) {\n\t\t\tonWildcardInUse?.(port);\n\t\t}\n\t\treturn port;\n\t}\n\tfor (let candidate = port; candidate <= MAX_PORT; candidate++) {\n\t\t// Why the wildcard check: a server on `::` and a server on `localhost` can share a port, and\n\t\t// then the browser can reach the other server.\n\t\tif (hostname == null || (await isFreeOnWildcard(candidate))) {\n\t\t\ttry {\n\t\t\t\tawait bind(server, candidate, hostname);\n\t\t\t\treturn candidate;\n\t\t\t} catch (error) {\n\t\t\t\tif (!isAddressInUse(error)) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tonPortInUse?.(candidate);\n\t}\n\tthrow new Error(`No open port from ${port} to ${MAX_PORT}.`);\n}\n\nasync function bind(server: Server, port: number, hostname: string | undefined): Promise<void> {\n\treturn new Promise<void>((resolve, reject) => {\n\t\tfunction onError(error: Error) {\n\t\t\tserver.off(\"listening\", onListening);\n\t\t\treject(error);\n\t\t}\n\t\tfunction onListening() {\n\t\t\tserver.off(\"error\", onError);\n\t\t\tresolve();\n\t\t}\n\t\tserver.once(\"error\", onError);\n\t\tserver.once(\"listening\", onListening);\n\t\tserver.listen(port, hostname);\n\t});\n}\n\nasync function isFreeOnWildcard(port: number): Promise<boolean> {\n\tconst probe = createServer();\n\ttry {\n\t\tawait bind(probe, port, undefined);\n\t} catch (error) {\n\t\tif (isAddressInUse(error)) {\n\t\t\treturn false;\n\t\t}\n\t\tthrow error;\n\t}\n\tawait new Promise<void>((resolve) => {\n\t\tprobe.close(() => {\n\t\t\tresolve();\n\t\t});\n\t});\n\treturn true;\n}\n\nfunction boundPort(server: Server, fallback: number): number {\n\tconst address = server.address();\n\treturn typeof address === \"object\" && address != null ? address.port : fallback;\n}\n\nfunction isAddressInUse(error: unknown): boolean {\n\treturn error instanceof Error && \"code\" in error && error.code === \"EADDRINUSE\";\n}\n","import { createServer as createHttpServer, IncomingMessage, ServerResponse } from \"node:http\";\nimport { getRequestListener } from \"@hono/node-server\";\nimport { errorAttributes, jsonSink } from \"../core/log.js\";\nimport { devServerStage } from \"../node/dev-server.js\";\nimport { exitAfterFlush } from \"../node/exit.js\";\nimport { listenerUrl } from \"../node/runtimes/listen-options.js\";\nimport { cancelIfClosed } from \"../node/runtimes/node.js\";\nimport { parsePort } from \"../node/tcp.js\";\nimport { SERVER_ENTRY_ID } from \"../vite/index.js\";\nimport { loadEntry } from \"./load-entry.js\";\nimport { servedApps } from \"./served-apps.js\";\nimport { listenFromPort } from \"./start-port.js\";\n\n/**\n * Runs the app in development: the same pipeline as production, with Vite in\n * middleware mode inside it. Each request loads the server entry through\n * Vite's SSR runner, so an edit to a route or to the app's `server.ts` applies\n * at once. HMR shares the port.\n *\n * The port is `--port`, else `PORT`, else Vite's `server.port`. When that port is in use, the\n * server tries each next port, unless Vite's `server.strictPort` is true. The\n * host is `HOST`, else Vite's `server.host`.\n */\nexport async function start(): Promise<void> {\n\tconst vite = await import(\"vite\");\n\tconst httpServer = createHttpServer();\n\tconst viteServer = await vite.createServer({\n\t\tserver: { middlewareMode: true, ws: { server: httpServer } },\n\t\tappType: \"custom\",\n\t});\n\t// Why read it for each request: a Vite restart, such as after a config edit, replaces the environments.\n\tconst ssrRunner = () => {\n\t\tconst { ssr } = viteServer.environments;\n\t\tif (ssr == null || !vite.isRunnableDevEnvironment(ssr)) {\n\t\t\tthrow new Error(\"Vite's SSR environment cannot run modules.\");\n\t\t}\n\t\treturn ssr.runner;\n\t};\n\tssrRunner();\n\tif (!viteServer.config.plugins.some((plugin) => plugin.name === \"@ngrok/app-server\")) {\n\t\tawait viteServer.close();\n\t\tthrow new Error(\n\t\t\t\"`app-server start` needs the `appServer` plugin from @ngrok/app-server/vite in the Vite config.\",\n\t\t);\n\t}\n\tconst devServer = devServerStage(viteServer.middlewares);\n\tconst sink = jsonSink();\n\tconst apps = servedApps();\n\n\tconst listener = getRequestListener(async (request, { incoming, outgoing }) => {\n\t\ttry {\n\t\t\tconst response = await apps.serve(\n\t\t\t\tawait loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)),\n\t\t\t\tasync (entry) =>\n\t\t\t\t\tentry.fetchDev(\n\t\t\t\t\t\trequest,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tremoteAddress: incoming.socket.remoteAddress,\n\t\t\t\t\t\t\t// Why the check: the listener is plain `node:http`, so these are always HTTP/1 objects.\n\t\t\t\t\t\t\t...(incoming instanceof IncomingMessage && outgoing instanceof ServerResponse\n\t\t\t\t\t\t\t\t? { incoming, outgoing }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdevServer,\n\t\t\t\t\t),\n\t\t\t);\n\t\t\treturn await cancelIfClosed(response, outgoing);\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tviteServer.ssrFixStacktrace(error);\n\t\t\t}\n\t\t\tsink.log(\"error\", \"dev request failed\", errorAttributes(error));\n\t\t\treturn new Response(error instanceof Error ? (error.stack ?? error.message) : String(error), {\n\t\t\t\tstatus: 500,\n\t\t\t\theaders: { \"Content-Type\": \"text/plain; charset=utf-8\" },\n\t\t\t});\n\t\t}\n\t});\n\thttpServer.on(\"request\", (request, response) => {\n\t\tvoid listener(request, response);\n\t});\n\n\tconst port =\n\t\tprocess.env.PORT == null ? viteServer.config.server.port : parsePort(process.env.PORT);\n\tconst hostname = process.env.HOST || viteHostname(viteServer.config.server.host);\n\tconst boundPort = await listenFromPort(httpServer, {\n\t\tport,\n\t\thostname,\n\t\tstrictPort: viteServer.config.server.strictPort,\n\t\tonPortInUse: (inUse) => {\n\t\t\tsink.log(\"info\", \"port in use, trying the next port\", { \"server.port\": inUse });\n\t\t},\n\t\tonWildcardInUse: (inUse) => {\n\t\t\tsink.log(\"warn\", \"port in use on a wildcard address\", {\n\t\t\t\t\"server.port\": inUse,\n\t\t\t\t\"server.address\": hostname,\n\t\t\t});\n\t\t},\n\t});\n\tsink.log(\"info\", \"listening\", { \"app_server.urls\": [listenerUrl(hostname, boundPort)] });\n\n\tfor (const signal of [\"SIGTERM\", \"SIGINT\"] as const) {\n\t\tprocess.once(signal, () => {\n\t\t\tconst pluginsStopped = apps.stopAll();\n\t\t\thttpServer.closeAllConnections();\n\t\t\tconst httpClosed = new Promise<void>((resolve) => {\n\t\t\t\thttpServer.close(() => {\n\t\t\t\t\tresolve();\n\t\t\t\t});\n\t\t\t});\n\t\t\tconst viteClosed = viteServer.close().catch((error: unknown) => {\n\t\t\t\tsink.log(\"error\", \"Vite close failed\", errorAttributes(error));\n\t\t\t\tprocess.exitCode = 1;\n\t\t\t});\n\t\t\tvoid Promise.all([pluginsStopped, httpClosed, viteClosed]).finally(exitAfterFlush);\n\t\t});\n\t}\n}\n\n/** The hostname for Vite's `server.host`: `true` is every interface, and no value is `localhost`. */\nfunction viteHostname(host: string | boolean | undefined): string | undefined {\n\tif (host === true) {\n\t\treturn undefined;\n\t}\n\treturn typeof host === \"string\" && host !== \"\" ? host : \"localhost\";\n}\n"],"mappings":"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"}
@@ -0,0 +1,11 @@
1
+ import { n as FrameworkBuild } from "./index-oSE-tYRW.js";
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
+ export declare function tanstackStartAdapter(): FrameworkBuild;
11
+ //# sourceMappingURL=tanstack-start-vite.d.ts.map
@@ -0,0 +1,24 @@
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
+ }
22
+
23
+ export { tanstackStartAdapter };
24
+ //# sourceMappingURL=tanstack-start-vite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-start-vite.js","names":[],"sources":["../src/tanstack-start/vite.ts"],"sourcesContent":["import type { FrameworkBuild } from \"../vite/index.js\";\n\n/**\n * The build side of the TanStack Start adapter. In `app-server start`, Vite\n * runs in middleware mode, so Start skips its own SSR middleware, and the\n * pipeline renders each page.\n *\n * @example\n * appServer({ framework: tanstackStartAdapter(), host: node(), app: \"./server.ts\" });\n */\nexport function tanstackStartAdapter(): FrameworkBuild {\n\treturn {\n\t\tname: \"tanstack-start\",\n\t\tserverModule: \"virtual:tanstack-start-server-entry\",\n\t\truntimeModule: \"@ngrok/app-server/tanstack-start\",\n\t\t// Why in the entry: Start defines `TSS_SERVER_FN_BASE` at build time, so only bundled code sees it.\n\t\truntimeOptions: \"{ serverFnBase: process.env.TSS_SERVER_FN_BASE }\",\n\t\t// Why this flag: Start sets it in the build process before it starts the preview server\n\t\t// of its prerender pass.\n\t\tisPrerenderPass: () => process.env.TSS_PRERENDERING === \"true\",\n\t\tvalidate: (config) => {\n\t\t\tif (config.base !== \"/\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`@ngrok/app-server serves a build at \"/\" only, and this config has the base \"${config.base}\".`,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,uBAAuC;CACtD,OAAO;EACN,MAAM;EACN,cAAc;EACd,eAAe;EAEf,gBAAgB;EAGhB,uBAAuB,QAAQ,IAAI,qBAAqB;EACxD,WAAW,WAAW;GACrB,IAAI,OAAO,SAAS,KACnB,MAAM,IAAI,MACT,+EAA+E,OAAO,KAAK,GAC5F;EAEF;CACD;AACD"}
@@ -0,0 +1,17 @@
1
+ import { f as Mode, i as FrameworkRuntime } from "./types-BfCkS7kQ.js";
2
+ /**
3
+ * 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
5
+ * request context. The server reads the prerendered paths that the Vite plugin
6
+ * recorded.
7
+ *
8
+ * @param info.serverFnBase - The prefix of Start's server functions, `TSS_SERVER_FN_BASE`. The entry that the Vite plugin generates sets it.
9
+ *
10
+ * @example
11
+ * const framework = runtime(await import("virtual:tanstack-start-server-entry"), { mode: "production" });
12
+ */
13
+ export declare function runtime(serverModule: unknown, { serverFnBase }: {
14
+ mode: Mode;
15
+ serverFnBase?: string;
16
+ }): FrameworkRuntime;
17
+ //# sourceMappingURL=tanstack-start.d.ts.map
@@ -0,0 +1,50 @@
1
+ // src/tanstack-start/index.ts
2
+ /** The prefix of Start's server functions when the config sets none. */
3
+ 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
+ /** Whether a module's default export is a TanStack Start server entry. */
13
+ function startServerEntry(module) {
14
+ if (typeof module !== "object" || module == null) return;
15
+ const entry = Reflect.get(module, "default");
16
+ if (typeof entry !== "object" || entry == null || !("fetch" in entry)) return;
17
+ const { fetch } = entry;
18
+ if (typeof fetch !== "function") return;
19
+ return { fetch: async (request, options) => {
20
+ 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.");
22
+ return response;
23
+ } };
24
+ }
25
+ /**
26
+ * 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
28
+ * request context. The server reads the prerendered paths that the Vite plugin
29
+ * recorded.
30
+ *
31
+ * @param info.serverFnBase - The prefix of Start's server functions, `TSS_SERVER_FN_BASE`. The entry that the Vite plugin generates sets it.
32
+ *
33
+ * @example
34
+ * const framework = runtime(await import("virtual:tanstack-start-server-entry"), { mode: "production" });
35
+ */
36
+ function runtime(serverModule, { serverFnBase = DEFAULT_SERVER_FN_BASE }) {
37
+ const entry = startServerEntry(serverModule);
38
+ if (entry == null) throw new Error("The server module has no TanStack Start server entry as its default export.");
39
+ return {
40
+ name: "tanstack-start",
41
+ 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
+ } } })
46
+ };
47
+ }
48
+
49
+ export { runtime };
50
+ //# sourceMappingURL=tanstack-start.js.map
@@ -0,0 +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"}
@@ -0,0 +1,41 @@
1
+ // src/node/tcp.ts
2
+ /** Above the ngrok edge's 90 s idle pool, so the edge never reuses a socket that the server is closing. */
3
+ const DEFAULT_IDLE_TIMEOUT_MS = 95e3;
4
+ /**
5
+ * Reads a port number. A value that is not an integer from 0 to 65535 throws,
6
+ * so a bad `PORT` stops startup.
7
+ *
8
+ * @example
9
+ * parsePort("8080"); // => 8080
10
+ */
11
+ function parsePort(value) {
12
+ const port = Number(value);
13
+ if (value.trim() === "" || !Number.isInteger(port) || port < 0 || port > 65535) throw new Error(`PORT must be an integer from 0 to 65535, not "${value}".`);
14
+ return port;
15
+ }
16
+ /**
17
+ * The default listener: a TCP port, served by the runtime's own HTTP server
18
+ * (`node:http` on Node, `Bun.serve` on Bun, `Deno.serve` on Deno). It reads
19
+ * `PORT` and `HOST` when it starts.
20
+ *
21
+ * @example
22
+ * createServer({ listeners: [tcp({ port: 8080 })] });
23
+ */
24
+ function tcp({ port, host, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS } = {}) {
25
+ return {
26
+ name: "tcp",
27
+ start: async (fetch) => {
28
+ const options = {
29
+ port: port ?? (process.env.PORT == null ? 3e3 : parsePort(process.env.PORT)),
30
+ hostname: host ?? (process.env.HOST || void 0),
31
+ idleTimeoutMs
32
+ };
33
+ 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);
36
+ }
37
+ };
38
+ }
39
+
40
+ export { tcp as n, parsePort as t };
41
+ //# sourceMappingURL=tcp-C-9AmFuM.js.map
@@ -0,0 +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"}