@ngrok/app-server 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -20
- package/dist/build-manifest-8NfD1wnO.js +45 -0
- package/dist/build-manifest-8NfD1wnO.js.map +1 -0
- package/dist/{bun-DCGnDEPn.js → bun-BCz6K_Xv.js} +12 -8
- package/dist/bun-BCz6K_Xv.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/cli.js.map +1 -1
- package/dist/{deno-BnMfk2n1.js → deno-DNRgzHrk.js} +4 -4
- package/dist/deno-DNRgzHrk.js.map +1 -0
- package/dist/{entry-ChjmFwX5.js → entry-BkdUub2S.js} +179 -296
- package/dist/entry-BkdUub2S.js.map +1 -0
- package/dist/index-oSE-tYRW.d.ts +88 -0
- package/dist/index.d.ts +212 -27
- package/dist/index.js +26 -15
- package/dist/index.js.map +1 -1
- package/dist/{listen-options-DHWmSWGi.js → listen-options-7TaXjyrk.js} +2 -2
- package/dist/listen-options-7TaXjyrk.js.map +1 -0
- package/dist/load-entry-C03qqmhr.js +33 -0
- package/dist/load-entry-C03qqmhr.js.map +1 -0
- package/dist/log-CsjaKM8U.js +59 -0
- package/dist/log-CsjaKM8U.js.map +1 -0
- package/dist/{node-79my3Uix.js → node-CG7qXuWZ.js} +4 -4
- package/dist/node-CG7qXuWZ.js.map +1 -0
- package/dist/node-YWPGmzAk.js +215 -0
- package/dist/node-YWPGmzAk.js.map +1 -0
- package/dist/node-ZMowKZDB.js +3 -0
- package/dist/node-vite.d.ts +10 -0
- package/dist/node-vite.js +18 -0
- package/dist/node-vite.js.map +1 -0
- package/dist/node.d.ts +67 -0
- package/dist/node.js +4 -0
- package/dist/react-router-vite.d.ts +9 -0
- package/dist/react-router-vite.js +21 -0
- package/dist/react-router-vite.js.map +1 -0
- package/dist/react-router.d.ts +11 -24
- package/dist/react-router.js +15 -25
- package/dist/react-router.js.map +1 -1
- package/dist/serve-Cleo8RMO.js +29 -0
- package/dist/serve-Cleo8RMO.js.map +1 -0
- package/dist/{start-BVMb8Pyt.js → start-CINALHxy.js} +92 -72
- package/dist/start-CINALHxy.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +11 -0
- package/dist/tanstack-start-vite.js +24 -0
- package/dist/tanstack-start-vite.js.map +1 -0
- package/dist/tanstack-start.d.ts +17 -0
- package/dist/tanstack-start.js +50 -0
- package/dist/tanstack-start.js.map +1 -0
- package/dist/{tcp-Dau_IONd.js → tcp-C-9AmFuM.js} +5 -5
- package/dist/tcp-C-9AmFuM.js.map +1 -0
- package/dist/types-BfCkS7kQ.d.ts +203 -0
- package/dist/vite-mYZ2Y69u.js +144 -0
- package/dist/vite-mYZ2Y69u.js.map +1 -0
- package/dist/vite.d.ts +2 -27
- package/dist/vite.js +2 -2
- package/package.json +28 -2
- package/dist/bun-DCGnDEPn.js.map +0 -1
- package/dist/captured-headers-ewL_t3MQ.js +0 -48
- package/dist/captured-headers-ewL_t3MQ.js.map +0 -1
- package/dist/deno-BnMfk2n1.js.map +0 -1
- package/dist/entry-CIpwaayZ.d.ts +0 -293
- package/dist/entry-ChjmFwX5.js.map +0 -1
- package/dist/listen-options-DHWmSWGi.js.map +0 -1
- package/dist/node-2wWBMFeO.js +0 -3
- package/dist/node-79my3Uix.js.map +0 -1
- package/dist/serve-ByeedcRB.js +0 -16
- package/dist/serve-ByeedcRB.js.map +0 -1
- package/dist/start-BVMb8Pyt.js.map +0 -1
- package/dist/tcp-Dau_IONd.js.map +0 -1
- package/dist/vite-CrNqpoeK.js +0 -102
- package/dist/vite-CrNqpoeK.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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"}
|
package/dist/react-router.d.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import {
|
|
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<
|
|
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
|
|
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 =
|
|
29
|
+
* const framework = runtime(build, { mode: "production" });
|
|
34
30
|
*/
|
|
35
|
-
export declare function
|
|
36
|
-
mode:
|
|
37
|
-
}):
|
|
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
|
package/dist/react-router.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 =
|
|
34
|
+
* const framework = runtime(build, { mode: "production" });
|
|
35
35
|
*/
|
|
36
|
-
function
|
|
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
|
-
|
|
41
|
+
name: "react-router",
|
|
42
|
+
clientDirectory: build.assetsBuildDirectory,
|
|
41
43
|
prerenderedPaths: build.prerender,
|
|
42
|
-
|
|
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,
|
|
57
|
+
export { appServerContext, isServerBuild, runtime };
|
|
68
58
|
//# sourceMappingURL=react-router.js.map
|
package/dist/react-router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-router.js","names":[],"sources":["../src/react-router.ts"],"sourcesContent":["import {
|
|
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"}
|
|
@@ -1,13 +1,66 @@
|
|
|
1
|
-
import { t as parsePort } from "./tcp-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
5
|
-
import { t as
|
|
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";
|
|
6
8
|
import { IncomingMessage, ServerResponse, createServer } from "node:http";
|
|
7
9
|
import { getRequestListener } from "@hono/node-server";
|
|
8
10
|
import { createServer as createServer$1 } from "node:net";
|
|
9
11
|
|
|
10
|
-
// src/
|
|
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
|
|
11
64
|
const MAX_PORT = 65535;
|
|
12
65
|
/**
|
|
13
66
|
* Starts `server` on `port`. When the port is in use, it tries each next port
|
|
@@ -37,16 +90,16 @@ async function listenFromPort(server, { port, hostname, strictPort, onPortInUse,
|
|
|
37
90
|
}
|
|
38
91
|
throw new Error(`No open port from ${port} to ${MAX_PORT}.`);
|
|
39
92
|
}
|
|
40
|
-
function bind(server, port, hostname) {
|
|
93
|
+
async function bind(server, port, hostname) {
|
|
41
94
|
return new Promise((resolve, reject) => {
|
|
42
|
-
|
|
95
|
+
function onError(error) {
|
|
43
96
|
server.off("listening", onListening);
|
|
44
97
|
reject(error);
|
|
45
|
-
}
|
|
46
|
-
|
|
98
|
+
}
|
|
99
|
+
function onListening() {
|
|
47
100
|
server.off("error", onError);
|
|
48
101
|
resolve();
|
|
49
|
-
}
|
|
102
|
+
}
|
|
50
103
|
server.once("error", onError);
|
|
51
104
|
server.once("listening", onListening);
|
|
52
105
|
server.listen(port, hostname);
|
|
@@ -75,57 +128,7 @@ function isAddressInUse(error) {
|
|
|
75
128
|
return error instanceof Error && "code" in error && error.code === "EADDRINUSE";
|
|
76
129
|
}
|
|
77
130
|
|
|
78
|
-
// src/
|
|
79
|
-
/**
|
|
80
|
-
* Tracks the apps that `app-server start` serves. An edit to `server.ts` makes a
|
|
81
|
-
* new app, and the old app's plugins still hold what their `setup` opened.
|
|
82
|
-
* When the last request that the old app took returns, its `onShutdown` hooks
|
|
83
|
-
* run, and the tracker lets go of it. A route edit makes a new entry with the
|
|
84
|
-
* same app, which keeps its plugins.
|
|
85
|
-
*/
|
|
86
|
-
function servedApps() {
|
|
87
|
-
let current;
|
|
88
|
-
const served = /* @__PURE__ */ new Set();
|
|
89
|
-
const retire = (app) => {
|
|
90
|
-
served.delete(app);
|
|
91
|
-
app.entry.stopPlugins();
|
|
92
|
-
};
|
|
93
|
-
return {
|
|
94
|
-
/** Runs `handle` for a request that `entry` serves. */
|
|
95
|
-
serve: async (entry, handle) => {
|
|
96
|
-
if (current?.entry.app === entry.app) current.entry = entry;
|
|
97
|
-
else {
|
|
98
|
-
if (current != null) {
|
|
99
|
-
current.replaced = true;
|
|
100
|
-
if (current.pending === 0) retire(current);
|
|
101
|
-
}
|
|
102
|
-
current = {
|
|
103
|
-
entry,
|
|
104
|
-
pending: 0,
|
|
105
|
-
replaced: false
|
|
106
|
-
};
|
|
107
|
-
served.add(current);
|
|
108
|
-
}
|
|
109
|
-
const app = current;
|
|
110
|
-
app.pending += 1;
|
|
111
|
-
try {
|
|
112
|
-
return await handle(entry);
|
|
113
|
-
} finally {
|
|
114
|
-
app.pending -= 1;
|
|
115
|
-
if (app.replaced && app.pending === 0) retire(app);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
/** At exit: aborts `shutdownSignal()` and runs the `onShutdown` hooks of each app still held. */
|
|
119
|
-
stopAll: () => {
|
|
120
|
-
for (const app of served) {
|
|
121
|
-
app.entry.abortShutdownSignal();
|
|
122
|
-
retire(app);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// src/start.ts
|
|
131
|
+
// src/cli/start.ts
|
|
129
132
|
/**
|
|
130
133
|
* Runs the app in development: the same pipeline as production, with Vite in
|
|
131
134
|
* middleware mode inside it. Each request loads the server entry through
|
|
@@ -147,23 +150,27 @@ async function start() {
|
|
|
147
150
|
appType: "custom"
|
|
148
151
|
});
|
|
149
152
|
const ssrRunner = () => {
|
|
150
|
-
const ssr = viteServer.environments
|
|
153
|
+
const { ssr } = viteServer.environments;
|
|
151
154
|
if (ssr == null || !vite.isRunnableDevEnvironment(ssr)) throw new Error("Vite's SSR environment cannot run modules.");
|
|
152
155
|
return ssr.runner;
|
|
153
156
|
};
|
|
154
157
|
ssrRunner();
|
|
155
|
-
|
|
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);
|
|
156
163
|
const sink = jsonSink();
|
|
157
164
|
const apps = servedApps();
|
|
158
165
|
const listener = getRequestListener(async (request, { incoming, outgoing }) => {
|
|
159
166
|
try {
|
|
160
|
-
const response = await apps.serve(await loadEntry(await ssrRunner().import(
|
|
167
|
+
const response = await apps.serve(await loadEntry(await ssrRunner().import(SERVER_ENTRY_ID)), async (entry) => entry.fetchDev(request, {
|
|
161
168
|
remoteAddress: incoming.socket.remoteAddress,
|
|
162
169
|
...incoming instanceof IncomingMessage && outgoing instanceof ServerResponse ? {
|
|
163
170
|
incoming,
|
|
164
171
|
outgoing
|
|
165
172
|
} : {}
|
|
166
|
-
},
|
|
173
|
+
}, devServer));
|
|
167
174
|
return await cancelIfClosed(response, outgoing);
|
|
168
175
|
} catch (error) {
|
|
169
176
|
if (error instanceof Error) viteServer.ssrFixStacktrace(error);
|
|
@@ -178,8 +185,7 @@ async function start() {
|
|
|
178
185
|
listener(request, response);
|
|
179
186
|
});
|
|
180
187
|
const port = process.env.PORT == null ? viteServer.config.server.port : parsePort(process.env.PORT);
|
|
181
|
-
const
|
|
182
|
-
const hostname = process.env.HOST || (configuredHost === true ? void 0 : configuredHost || "localhost");
|
|
188
|
+
const hostname = process.env.HOST || viteHostname(viteServer.config.server.host);
|
|
183
189
|
const boundPort = await listenFromPort(httpServer, {
|
|
184
190
|
port,
|
|
185
191
|
hostname,
|
|
@@ -196,15 +202,29 @@ async function start() {
|
|
|
196
202
|
});
|
|
197
203
|
sink.log("info", "listening", { "app_server.urls": [listenerUrl(hostname, boundPort)] });
|
|
198
204
|
for (const signal of ["SIGTERM", "SIGINT"]) process.once(signal, () => {
|
|
199
|
-
apps.stopAll();
|
|
205
|
+
const pluginsStopped = apps.stopAll();
|
|
200
206
|
httpServer.closeAllConnections();
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
const httpClosed = new Promise((resolve) => {
|
|
208
|
+
httpServer.close(() => {
|
|
209
|
+
resolve();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
const viteClosed = viteServer.close().catch((error) => {
|
|
203
213
|
sink.log("error", "Vite close failed", errorAttributes(error));
|
|
204
214
|
process.exitCode = 1;
|
|
205
215
|
});
|
|
216
|
+
Promise.all([
|
|
217
|
+
pluginsStopped,
|
|
218
|
+
httpClosed,
|
|
219
|
+
viteClosed
|
|
220
|
+
]).finally(exitAfterFlush);
|
|
206
221
|
});
|
|
207
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
|
+
}
|
|
208
228
|
|
|
209
229
|
export { start };
|
|
210
|
-
//# sourceMappingURL=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":";;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,aAAyB;CACxC,IAAI;CACJ,MAAM,yBAAS,IAAI,IAAe;CAGlC,MAAM,SAAS,OAAO,QAAmB;EACxC,IAAI;GACH,MAAM,IAAI,MAAM,YAAY;EAC7B,UAAU;GACT,OAAO,OAAO,GAAG;EAClB;CACD;CACA,OAAO;EACN,OAAO,OAAO,OAAO,WAAW;GAC/B,IAAI,SAAS,MAAM,QAAQ,MAAM,KAChC,QAAQ,QAAQ;QACV;IACN,IAAI,WAAW,MAAM;KACpB,QAAQ,WAAW;KACnB,IAAI,QAAQ,YAAY,GACvB,AAAK,OAAO,OAAO;IAErB;IACA,UAAU;KAAE;KAAO,SAAS;KAAG,UAAU;IAAM;IAC/C,OAAO,IAAI,OAAO;GACnB;GACA,MAAM,MAAM;GACZ,IAAI,WAAW;GACf,IAAI;IACH,OAAO,MAAM,OAAO,KAAK;GAC1B,UAAU;IACT,IAAI,WAAW;IACf,IAAI,IAAI,YAAY,IAAI,YAAY,GACnC,AAAK,OAAO,GAAG;GAEjB;EACD;EACA,SAAS,YAAY;GACpB,MAAM,QAAQ,IACb,MAAM,KAAK,QAAQ,OAAO,QAAQ;IACjC,IAAI,MAAM,oBAAoB;IAC9B,MAAM,OAAO,GAAG;GACjB,CAAC,CACF;EACD;CACD;AACD;;;ACpEA,MAAM,WAAW;;;;;;;AAyBjB,eAAsB,eACrB,QACA,EAAE,MAAM,UAAU,YAAY,aAAa,mBACzB;CAClB,IAAI,SAAS,GAAG;EACf,MAAM,KAAK,QAAQ,MAAM,QAAQ;EACjC,OAAO,UAAU,QAAQ,IAAI;CAC9B;CACA,IAAI,YAAY;EAGf,MAAM,iBAAiB,YAAY,QAAS,MAAM,iBAAiB,IAAI;EACvE,MAAM,KAAK,QAAQ,MAAM,QAAQ;EACjC,IAAI,CAAC,gBACJ,kBAAkB,IAAI;EAEvB,OAAO;CACR;CACA,KAAK,IAAI,YAAY,MAAM,aAAa,UAAU,aAAa;EAG9D,IAAI,YAAY,QAAS,MAAM,iBAAiB,SAAS,GACxD,IAAI;GACH,MAAM,KAAK,QAAQ,WAAW,QAAQ;GACtC,OAAO;EACR,SAAS,OAAO;GACf,IAAI,CAAC,eAAe,KAAK,GACxB,MAAM;EAER;EAED,cAAc,SAAS;CACxB;CACA,MAAM,IAAI,MAAM,qBAAqB,KAAK,MAAM,SAAS,EAAE;AAC5D;AAEA,eAAe,KAAK,QAAgB,MAAc,UAA6C;CAC9F,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,SAAS,QAAQ,OAAc;GAC9B,OAAO,IAAI,aAAa,WAAW;GACnC,OAAO,KAAK;EACb;EACA,SAAS,cAAc;GACtB,OAAO,IAAI,SAAS,OAAO;GAC3B,QAAQ;EACT;EACA,OAAO,KAAK,SAAS,OAAO;EAC5B,OAAO,KAAK,aAAa,WAAW;EACpC,OAAO,OAAO,MAAM,QAAQ;CAC7B,CAAC;AACF;AAEA,eAAe,iBAAiB,MAAgC;CAC/D,MAAM,QAAQA,eAAa;CAC3B,IAAI;EACH,MAAM,KAAK,OAAO,MAAM,MAAS;CAClC,SAAS,OAAO;EACf,IAAI,eAAe,KAAK,GACvB,OAAO;EAER,MAAM;CACP;CACA,MAAM,IAAI,SAAe,YAAY;EACpC,MAAM,YAAY;GACjB,QAAQ;EACT,CAAC;CACF,CAAC;CACD,OAAO;AACR;AAEA,SAAS,UAAU,QAAgB,UAA0B;CAC5D,MAAM,UAAU,OAAO,QAAQ;CAC/B,OAAO,OAAO,YAAY,YAAY,WAAW,OAAO,QAAQ,OAAO;AACxE;AAEA,SAAS,eAAe,OAAyB;CAChD,OAAO,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS;AACpE;;;;;;;;;;;;;AClFA,eAAsB,QAAuB;CAC5C,MAAM,OAAO,MAAM,OAAO;CAC1B,MAAM,aAAaC,aAAiB;CACpC,MAAM,aAAa,MAAM,KAAK,aAAa;EAC1C,QAAQ;GAAE,gBAAgB;GAAM,IAAI,EAAE,QAAQ,WAAW;EAAE;EAC3D,SAAS;CACV,CAAC;CAED,MAAM,kBAAkB;EACvB,MAAM,EAAE,QAAQ,WAAW;EAC3B,IAAI,OAAO,QAAQ,CAAC,KAAK,yBAAyB,GAAG,GACpD,MAAM,IAAI,MAAM,4CAA4C;EAE7D,OAAO,IAAI;CACZ;CACA,UAAU;CACV,IAAI,CAAC,WAAW,OAAO,QAAQ,MAAM,WAAW,OAAO,SAAS,mBAAmB,GAAG;EACrF,MAAM,WAAW,MAAM;EACvB,MAAM,IAAI,MACT,iGACD;CACD;CACA,MAAM,YAAY,eAAe,WAAW,WAAW;CACvD,MAAM,OAAO,SAAS;CACtB,MAAM,OAAO,WAAW;CAExB,MAAM,WAAW,mBAAmB,OAAO,SAAS,EAAE,UAAU,eAAe;EAC9E,IAAI;GACH,MAAM,WAAW,MAAM,KAAK,MAC3B,MAAM,UAAU,MAAM,UAAU,CAAC,CAAC,OAAO,eAAe,CAAC,GACzD,OAAO,UACN,MAAM,SACL,SACA;IACC,eAAe,SAAS,OAAO;IAE/B,GAAI,oBAAoB,mBAAmB,oBAAoB,iBAC5D;KAAE;KAAU;IAAS,IACrB,CAAC;GACL,GACA,SACD,CACF;GACA,OAAO,MAAM,eAAe,UAAU,QAAQ;EAC/C,SAAS,OAAO;GACf,IAAI,iBAAiB,OACpB,WAAW,iBAAiB,KAAK;GAElC,KAAK,IAAI,SAAS,sBAAsB,gBAAgB,KAAK,CAAC;GAC9D,OAAO,IAAI,SAAS,iBAAiB,QAAS,MAAM,SAAS,MAAM,UAAW,OAAO,KAAK,GAAG;IAC5F,QAAQ;IACR,SAAS,EAAE,gBAAgB,4BAA4B;GACxD,CAAC;EACF;CACD,CAAC;CACD,WAAW,GAAG,YAAY,SAAS,aAAa;EAC/C,AAAK,SAAS,SAAS,QAAQ;CAChC,CAAC;CAED,MAAM,OACL,QAAQ,IAAI,QAAQ,OAAO,WAAW,OAAO,OAAO,OAAO,UAAU,QAAQ,IAAI,IAAI;CACtF,MAAM,WAAW,QAAQ,IAAI,QAAQ,aAAa,WAAW,OAAO,OAAO,IAAI;CAC/E,MAAM,YAAY,MAAM,eAAe,YAAY;EAClD;EACA;EACA,YAAY,WAAW,OAAO,OAAO;EACrC,cAAc,UAAU;GACvB,KAAK,IAAI,QAAQ,qCAAqC,EAAE,eAAe,MAAM,CAAC;EAC/E;EACA,kBAAkB,UAAU;GAC3B,KAAK,IAAI,QAAQ,qCAAqC;IACrD,eAAe;IACf,kBAAkB;GACnB,CAAC;EACF;CACD,CAAC;CACD,KAAK,IAAI,QAAQ,aAAa,EAAE,mBAAmB,CAAC,YAAY,UAAU,SAAS,CAAC,EAAE,CAAC;CAEvF,KAAK,MAAM,UAAU,CAAC,WAAW,QAAQ,GACxC,QAAQ,KAAK,cAAc;EAC1B,MAAM,iBAAiB,KAAK,QAAQ;EACpC,WAAW,oBAAoB;EAC/B,MAAM,aAAa,IAAI,SAAe,YAAY;GACjD,WAAW,YAAY;IACtB,QAAQ;GACT,CAAC;EACF,CAAC;EACD,MAAM,aAAa,WAAW,MAAM,CAAC,CAAC,OAAO,UAAmB;GAC/D,KAAK,IAAI,SAAS,qBAAqB,gBAAgB,KAAK,CAAC;GAC7D,QAAQ,WAAW;EACpB,CAAC;EACD,AAAK,QAAQ,IAAI;GAAC;GAAgB;GAAY;EAAU,CAAC,CAAC,CAAC,QAAQ,cAAc;CAClF,CAAC;AAEH;;AAGA,SAAS,aAAa,MAAwD;CAC7E,IAAI,SAAS,MACZ;CAED,OAAO,OAAO,SAAS,YAAY,SAAS,KAAK,OAAO;AACzD"}
|
|
@@ -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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/tcp.ts
|
|
1
|
+
// src/node/tcp.ts
|
|
2
2
|
/** Above the ngrok edge's 90 s idle pool, so the edge never reuses a socket that the server is closing. */
|
|
3
3
|
const DEFAULT_IDLE_TIMEOUT_MS = 95e3;
|
|
4
4
|
/**
|
|
@@ -30,12 +30,12 @@ function tcp({ port, host, idleTimeoutMs = DEFAULT_IDLE_TIMEOUT_MS } = {}) {
|
|
|
30
30
|
hostname: host ?? (process.env.HOST || void 0),
|
|
31
31
|
idleTimeoutMs
|
|
32
32
|
};
|
|
33
|
-
if ("Bun" in globalThis) return (await import("./bun-
|
|
34
|
-
if ("Deno" in globalThis) return (await import("./deno-
|
|
35
|
-
return (await import("./node-
|
|
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
36
|
}
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export { tcp as n, parsePort as t };
|
|
41
|
-
//# sourceMappingURL=tcp-
|
|
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"}
|