@ngrok/app-server 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +652 -77
- package/dist/build-id-C6sYO9Yp.js +126 -0
- package/dist/build-id-C6sYO9Yp.js.map +1 -0
- package/dist/{build-manifest-8NfD1wnO.js → build-manifest-UDNk81Ce.js} +24 -6
- package/dist/build-manifest-UDNk81Ce.js.map +1 -0
- package/dist/cli.js +45 -25
- package/dist/cli.js.map +1 -1
- package/dist/client-browser.d.ts +12 -0
- package/dist/client-browser.js +3 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +27 -0
- package/dist/client.js.map +1 -0
- package/dist/compression-7_gToa8R.js +97 -0
- package/dist/compression-7_gToa8R.js.map +1 -0
- package/dist/create-server-DkTeIJ8L.js +1409 -0
- package/dist/create-server-DkTeIJ8L.js.map +1 -0
- package/dist/{deno-DNRgzHrk.js → deno-aqhikNMG.js} +2 -2
- package/dist/deno-aqhikNMG.js.map +1 -0
- package/dist/entry-CM6Ma-Tv.d.ts +626 -0
- package/dist/entry-CenmvESk.js +116 -0
- package/dist/entry-CenmvESk.js.map +1 -0
- package/dist/gzip-Doi4wqjX.js +294 -0
- package/dist/gzip-Doi4wqjX.js.map +1 -0
- package/dist/header-hook-Vzw9J9BY.js +159 -0
- package/dist/header-hook-Vzw9J9BY.js.map +1 -0
- package/dist/{index-oSE-tYRW.d.ts → index-Bo5G9LuQ.d.ts} +53 -14
- package/dist/index.d.ts +99 -269
- package/dist/index.js +47 -59
- package/dist/index.js.map +1 -1
- package/dist/listen-options-7TaXjyrk.js.map +1 -1
- package/dist/{load-entry-C03qqmhr.js → load-entry-CmkdlmDX.js} +8 -4
- package/dist/{load-entry-C03qqmhr.js.map → load-entry-CmkdlmDX.js.map} +1 -1
- package/dist/log-BP6xXXZl.js +122 -0
- package/dist/log-BP6xXXZl.js.map +1 -0
- package/dist/node-BFH82eeL.js +333 -0
- package/dist/node-BFH82eeL.js.map +1 -0
- package/dist/node-tBVQPjQv.js +41 -0
- package/dist/node-tBVQPjQv.js.map +1 -0
- package/dist/node-vite.d.ts +5 -4
- package/dist/node-vite.js +2 -17
- package/dist/node.d.ts +23 -4
- package/dist/node.js +2 -2
- package/dist/react-router-vite.d.ts +4 -3
- package/dist/react-router-vite.js +2 -20
- package/dist/react-router.d.ts +1 -1
- package/dist/react-router.js +8 -7
- package/dist/react-router.js.map +1 -1
- package/dist/request-context-BtQ87VYb.js +40 -0
- package/dist/request-context-BtQ87VYb.js.map +1 -0
- package/dist/response-edge-Bc1-C_Cx.js +327 -0
- package/dist/response-edge-Bc1-C_Cx.js.map +1 -0
- package/dist/response-writer-B7FoJjEE.js +289 -0
- package/dist/response-writer-B7FoJjEE.js.map +1 -0
- package/dist/script-hashes-hqUk6kG7.js +53 -0
- package/dist/script-hashes-hqUk6kG7.js.map +1 -0
- package/dist/{serve-Cleo8RMO.js → serve-Cc-ADdhZ.js} +3 -3
- package/dist/{serve-Cleo8RMO.js.map → serve-Cc-ADdhZ.js.map} +1 -1
- package/dist/stale-build-navigation-PnMLtTF8.js +339 -0
- package/dist/stale-build-navigation-PnMLtTF8.js.map +1 -0
- package/dist/stale-build-navigation-ypV7Ow4o.d.ts +141 -0
- package/dist/{start-CINALHxy.js → start-Cb3kknlF.js} +14 -19
- package/dist/start-Cb3kknlF.js.map +1 -0
- package/dist/static-files-Beju9riB.js +302 -0
- package/dist/static-files-Beju9riB.js.map +1 -0
- package/dist/tanstack-start-vite.d.ts +6 -5
- package/dist/tanstack-start-vite.js +2 -23
- package/dist/tanstack-start.d.ts +19 -2
- package/dist/tanstack-start.js +5 -14
- package/dist/tanstack-start.js.map +1 -1
- package/dist/{tcp-C-9AmFuM.js → tcp-Dd1Mt6sN.js} +6 -5
- package/dist/{tcp-C-9AmFuM.js.map → tcp-Dd1Mt6sN.js.map} +1 -1
- package/dist/trailing-slash-DX7NB88H.d.ts +36 -0
- package/dist/types-DLYxYS6M.d.ts +392 -0
- package/dist/vercel-vite.d.ts +35 -0
- package/dist/vercel-vite.js +142 -0
- package/dist/vercel-vite.js.map +1 -0
- package/dist/vercel.d.ts +35 -0
- package/dist/vercel.js +89 -0
- package/dist/vercel.js.map +1 -0
- package/dist/vite-B-GfswoH.js +22 -0
- package/dist/vite-B-GfswoH.js.map +1 -0
- package/dist/vite-D4hfj3ph.js +19 -0
- package/dist/vite-D4hfj3ph.js.map +1 -0
- package/dist/vite-DyrhyKEr.js +25 -0
- package/dist/vite-DyrhyKEr.js.map +1 -0
- package/dist/vite-iioAoxSt.js +752 -0
- package/dist/vite-iioAoxSt.js.map +1 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +1 -1
- package/package.json +25 -4
- package/dist/build-manifest-8NfD1wnO.js.map +0 -1
- package/dist/deno-DNRgzHrk.js.map +0 -1
- package/dist/entry-BkdUub2S.js +0 -638
- package/dist/entry-BkdUub2S.js.map +0 -1
- package/dist/log-CsjaKM8U.js +0 -59
- package/dist/log-CsjaKM8U.js.map +0 -1
- package/dist/node-CG7qXuWZ.js +0 -58
- package/dist/node-CG7qXuWZ.js.map +0 -1
- package/dist/node-YWPGmzAk.js +0 -215
- package/dist/node-YWPGmzAk.js.map +0 -1
- package/dist/node-ZMowKZDB.js +0 -3
- package/dist/node-vite.js.map +0 -1
- package/dist/react-router-vite.js.map +0 -1
- package/dist/start-CINALHxy.js.map +0 -1
- package/dist/tanstack-start-vite.js.map +0 -1
- package/dist/types-BfCkS7kQ.d.ts +0 -203
- package/dist/vite-mYZ2Y69u.js +0 -144
- package/dist/vite-mYZ2Y69u.js.map +0 -1
|
@@ -37,14 +37,39 @@ type HostBuild = {
|
|
|
37
37
|
runtimeModule: string;
|
|
38
38
|
/** The file name of the server entry in the server build, such as `app-server.js`. */
|
|
39
39
|
entryFileName: string;
|
|
40
|
+
/**
|
|
41
|
+
* Writes the host's deploy output, such as Vercel's `.vercel/output`. It
|
|
42
|
+
* runs after each prerender pass and after the build, so it can run two
|
|
43
|
+
* times. Why after the pass too: when `appServer` comes before the
|
|
44
|
+
* framework's plugin, the pass runs after the build. Why sync: Vite does
|
|
45
|
+
* not wait for the end of that pass.
|
|
46
|
+
*/
|
|
47
|
+
output?: (build: HostOutput) => void;
|
|
48
|
+
};
|
|
49
|
+
/** What a host's `output` gets: the absolute paths of the build. */
|
|
50
|
+
type HostOutput = {
|
|
51
|
+
/** The Vite root. */
|
|
52
|
+
root: string;
|
|
53
|
+
/** The client build, such as `build/client`. */
|
|
54
|
+
clientDirectory: string;
|
|
55
|
+
/** The server entry, such as `build/server/app-server.js`. */
|
|
56
|
+
entryFile: string;
|
|
40
57
|
};
|
|
41
58
|
/** Options for {@link appServer}. */
|
|
42
59
|
type AppServerOptions = {
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The framework adapter. When omitted, the plugin finds the React Router or
|
|
62
|
+
* TanStack Start plugin in the Vite config. It throws when it finds neither
|
|
63
|
+
* or both.
|
|
64
|
+
*/
|
|
65
|
+
framework?: FrameworkBuild;
|
|
66
|
+
/** The host adapter. Default `node()`. */
|
|
67
|
+
host?: HostBuild;
|
|
45
68
|
/**
|
|
46
69
|
* The module whose default export is the app from `createServer`, relative
|
|
47
|
-
* to the Vite root. When omitted, the
|
|
70
|
+
* to the Vite root. When omitted, the plugin uses `server.ts`, else
|
|
71
|
+
* `server.js`, in the Vite root. When neither exists, the server uses its
|
|
72
|
+
* default plugins.
|
|
48
73
|
*/
|
|
49
74
|
app?: string;
|
|
50
75
|
};
|
|
@@ -57,7 +82,11 @@ type EntrySource = {
|
|
|
57
82
|
/** The source of an expression that gives the client build: a path or a `file:` URL. */
|
|
58
83
|
clientDirectory: string;
|
|
59
84
|
};
|
|
60
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* The source of the server entry. When a runtime runs the file as its main
|
|
87
|
+
* module, such as `node build/server/app-server.js`, the entry starts the
|
|
88
|
+
* server. When the CLI imports it, the CLI starts the server.
|
|
89
|
+
*/
|
|
61
90
|
declare function serverEntrySource({ framework, host, appModule, clientDirectory }: EntrySource): string;
|
|
62
91
|
/**
|
|
63
92
|
* The Vite plugin for `@ngrok/app-server`. Put it next to the framework's
|
|
@@ -67,22 +96,32 @@ declare function serverEntrySource({ framework, host, appModule, clientDirectory
|
|
|
67
96
|
* `build/server/app-server.js` on the node host. The entry bundles the app
|
|
68
97
|
* (the default export of `app`) with the framework's server module, so the
|
|
69
98
|
* server gets the app's path aliases and its one copy of the framework.
|
|
70
|
-
* The framework's own entry does not change.
|
|
99
|
+
* The framework's own entry does not change. When a runtime runs the entry
|
|
100
|
+
* as its main module, the entry starts the server.
|
|
101
|
+
* - In a build, it bundles each dependency into the server build. It copies
|
|
102
|
+
* each package that stays external into `node_modules` in the server build.
|
|
103
|
+
* So the build directory runs with no install.
|
|
104
|
+
* - After the client build, it writes `.app-server.json` in the client
|
|
105
|
+
* build with the build ID: a hash of the client bundle. After the build,
|
|
106
|
+
* it adds the files that the server build wrote to the client's assets
|
|
107
|
+
* directory, such as React Router's route manifest. The `buildId` plugin
|
|
108
|
+
* sends the ID.
|
|
71
109
|
* - During the framework's prerender pass, it records each prerendered path
|
|
72
110
|
* and the headers of each prerendered file that is not an HTML document into
|
|
73
111
|
* `.app-server.json` in the client build. The `prerendered` plugin replays
|
|
74
112
|
* the headers. A document's headers depend on its request, so they are not
|
|
75
113
|
* recorded.
|
|
114
|
+
* - After the build and after the prerender pass, it records the hash of each
|
|
115
|
+
* inline script of each HTML file in `.app-server.json`, for the
|
|
116
|
+
* `contentSecurityPolicy` plugin. It also writes a gzip copy (`.<file>.gz`)
|
|
117
|
+
* and a brotli copy (`.<file>.br`) next to each text file of 1 KiB or more
|
|
118
|
+
* in the client build, HTML included. The static stages send a copy, so the
|
|
119
|
+
* server does not compress these files for each request.
|
|
76
120
|
*
|
|
77
121
|
* @example
|
|
78
122
|
* // vite.config.ts
|
|
79
|
-
* export default defineConfig({
|
|
80
|
-
* plugins: [
|
|
81
|
-
* reactRouter(),
|
|
82
|
-
* appServer({ framework: reactRouterAdapter(), host: node(), app: "./server.ts" }),
|
|
83
|
-
* ],
|
|
84
|
-
* });
|
|
123
|
+
* export default defineConfig({ plugins: [reactRouter(), appServer()] });
|
|
85
124
|
*/
|
|
86
|
-
declare function appServer(
|
|
87
|
-
export {
|
|
88
|
-
//# sourceMappingURL=index-
|
|
125
|
+
declare function appServer(options?: AppServerOptions): Plugin[];
|
|
126
|
+
export { SERVER_ENTRY_ID as a, HostOutput as i, FrameworkBuild as n, appServer as o, HostBuild as r, serverEntrySource as s, AppServerOptions as t };
|
|
127
|
+
//# sourceMappingURL=index-Bo5G9LuQ.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,194 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Replace each query value with `REDACTED`, so a single-use code in a URL
|
|
7
|
-
* never reaches a log.
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
redactQuery?: boolean;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* One log line per request, static hits included, with Datadog standard
|
|
14
|
-
* attribute names. The line goes out when the body ends or the client
|
|
15
|
-
* disconnects, so a streamed response logs its full duration and size.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* createServer({ plugins: [requestId(), accessLog({ redactQuery: false })] });
|
|
19
|
-
* // {"level":"info","message":"request","http.status_code":200,"network.bytes_written":5120,"duration":1830000,...}
|
|
20
|
-
*/
|
|
21
|
-
export declare function accessLog({ redactQuery }?: AccessLogOptions): Plugin;
|
|
22
|
-
/** Options for {@link requestId}. */
|
|
23
|
-
type RequestIdOptions = {
|
|
24
|
-
/** @default "X-Request-Id" */
|
|
25
|
-
headerName?: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Gives each request an ID: a valid incoming header (up to 255 word
|
|
29
|
-
* characters, `-`, and `=`), else a new UUID. The ID goes on the response, on
|
|
30
|
-
* every log line, and into the framework's context.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const app = createServer({ plugins: [requestId()] });
|
|
34
|
-
* const response = await app.request("/", { headers: { "X-Request-Id": "abc-123" } });
|
|
35
|
-
* response.headers.get("X-Request-Id"); // => "abc-123"
|
|
36
|
-
*/
|
|
37
|
-
export declare function requestId({ headerName }?: RequestIdOptions): Plugin;
|
|
38
|
-
/**
|
|
39
|
-
* Serves the hashed files under `/assets/` with a one-year immutable cache.
|
|
40
|
-
* A missing asset gets a plain 404, not a rendered page. In development,
|
|
41
|
-
* the dev server serves the source modules, the HMR client, and the CSS here
|
|
42
|
-
* instead.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* createServer({ plugins: [requestId(), accessLog(), streamingCompress(), assets(), prerendered()] });
|
|
46
|
-
*/
|
|
47
|
-
export declare function assets(): Plugin;
|
|
48
|
-
/** Options for {@link prerendered}. */
|
|
49
|
-
type PrerenderedOptions = {
|
|
50
|
-
/**
|
|
51
|
-
* Extra headers for a served file, by its URL path. They replace the
|
|
52
|
-
* headers captured at build time.
|
|
53
|
-
*/
|
|
54
|
-
headers?: (path: string, context: Context<AppServerEnv>) => Readonly<Record<string, string>> | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Maps a request path to the URL path of the file to serve, for content
|
|
57
|
-
* negotiation. Return the path unchanged to serve the usual file. The
|
|
58
|
-
* returned path follows the rules of a request path: one URL for each
|
|
59
|
-
* file, no dotfiles, and nothing outside the client build. When the
|
|
60
|
-
* answer depends on a request header, add a `Vary` for it in a plugin.
|
|
61
|
-
*/
|
|
62
|
-
rewrite?: (path: string, context: Context<AppServerEnv>) => string;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Serves the client build: prerendered pages at their own URL with a 200 and
|
|
66
|
-
* no trailing-slash redirect, plus every other file in it. Each response gets
|
|
67
|
-
* the headers its loader sent at build time (the `appServer` Vite plugin
|
|
68
|
-
* captures them), an ETag, and a 304 for a matching `If-None-Match`. A path
|
|
69
|
-
* with no file goes on to the framework. Off in development.
|
|
70
|
-
*
|
|
71
|
-
* At startup, it warns about each prerendered path that has no file.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* prerendered({
|
|
75
|
-
* headers: (path) => (path.startsWith("/api/") ? { "Access-Control-Allow-Origin": "*" } : undefined),
|
|
76
|
-
* });
|
|
77
|
-
*/
|
|
78
|
-
export declare function prerendered(options?: PrerenderedOptions): Plugin;
|
|
79
|
-
/** A Hono app from {@link createServer}. Add routes to it before you export it. */
|
|
80
|
-
type AppServer = Hono<AppServerEnv>;
|
|
81
|
-
/** A server that listens. */
|
|
82
|
-
type RunningServer = {
|
|
83
|
-
/** The URL of each listener. */
|
|
84
|
-
urls: readonly string[];
|
|
85
|
-
/**
|
|
86
|
-
* Aborts `shutdownSignal()`, then runs each plugin's `onShutdown` while the
|
|
87
|
-
* listeners stop and drain open requests. Both stop at the deadline.
|
|
88
|
-
*/
|
|
89
|
-
shutdown: () => Promise<void>;
|
|
90
|
-
};
|
|
91
|
-
/** Options for {@link defaultPlugins}. */
|
|
92
|
-
type DefaultPluginsOptions = {
|
|
93
|
-
requestId?: RequestIdOptions;
|
|
94
|
-
accessLog?: AccessLogOptions;
|
|
95
|
-
prerendered?: PrerenderedOptions;
|
|
96
|
-
/**
|
|
97
|
-
* Plugins that go after compression and before the static stages, so they
|
|
98
|
-
* see every response, prerendered pages included. `runtimeEnv` and
|
|
99
|
-
* `buildId` go here.
|
|
100
|
-
*/
|
|
101
|
-
beforeStatic?: readonly Plugin[];
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* The default pipeline, in order: `requestId`, `accessLog`,
|
|
105
|
-
* `streamingCompress`, the `beforeStatic` plugins, `assets`, and
|
|
106
|
-
* `prerendered`. It is a plain array, so an app can filter it or splice into it.
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* createServer({ plugins: defaultPlugins({ accessLog: { redactQuery: false }, beforeStatic: [env] }) });
|
|
110
|
-
*/
|
|
111
|
-
export declare function defaultPlugins(options?: DefaultPluginsOptions): Plugin[];
|
|
112
|
-
/** Options for {@link createServer}. */
|
|
113
|
-
type CreateServerOptions = {
|
|
114
|
-
/** @default defaultPlugins() */
|
|
115
|
-
plugins?: readonly Plugin[];
|
|
116
|
-
/** @default jsonSink() */
|
|
117
|
-
logger?: LogSink;
|
|
118
|
-
/** @default the host's listeners, such as `[tcp()]` on the node host */
|
|
119
|
-
listeners?: readonly Listener[];
|
|
120
|
-
/**
|
|
121
|
-
* Read the request scheme from `X-Forwarded-Proto`. Set it only behind a
|
|
122
|
-
* proxy that overwrites that header, else a client can spoof it.
|
|
123
|
-
* @default false
|
|
124
|
-
*/
|
|
125
|
-
trustForwardedProto?: boolean;
|
|
126
|
-
/**
|
|
127
|
-
* How long open requests get to finish after a stop signal.
|
|
128
|
-
* @default 10000
|
|
129
|
-
*/
|
|
130
|
-
shutdownDeadlineMs?: number;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Builds an app server: a Hono app that runs the plugins in list order, then
|
|
134
|
-
* the app's own routes, then the framework. It does not listen; the
|
|
135
|
-
* `app-server` CLI starts it.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* // server.ts
|
|
139
|
-
* const app = createServer({ logger: slogSink, plugins: defaultPlugins({ beforeStatic: [env] }) });
|
|
140
|
-
* app.get("/livez", (c) => c.text("ok"));
|
|
141
|
-
* export default app;
|
|
142
|
-
*/
|
|
143
|
-
export declare function createServer({ plugins, logger, listeners, trustForwardedProto, shutdownDeadlineMs }?: CreateServerOptions): AppServer;
|
|
144
|
-
/** The version of the contract between the CLI and the `appServer` export of a build. */
|
|
145
|
-
declare const ENTRY_PROTOCOL = 2;
|
|
146
|
-
/**
|
|
147
|
-
* What a server build exports as `appServer`. The CLI calls it, so the copy
|
|
148
|
-
* of this package in the build runs the server, and the CLI's copy runs
|
|
149
|
-
* nothing.
|
|
150
|
-
*/
|
|
151
|
-
type AppServerEntry = {
|
|
152
|
-
/** The CLI refuses an entry with another version. */
|
|
153
|
-
protocol: typeof ENTRY_PROTOCOL;
|
|
154
|
-
/** The app. Two entries with the same app share its plugins. */
|
|
155
|
-
app: AppServer;
|
|
156
|
-
/**
|
|
157
|
-
* Production: runs each plugin's `setup` and listens. When the host's
|
|
158
|
-
* lifecycle stops, such as on `SIGTERM`, it shuts down.
|
|
159
|
-
*/
|
|
160
|
-
start: () => Promise<void>;
|
|
161
|
-
/** Development: answers one request with the dev server inside the pipeline. */
|
|
162
|
-
fetchDev: (request: Request, bindings: ListenerBindings, devServer: MiddlewareHandler<AppServerEnv>) => Promise<Response>;
|
|
163
|
-
/** Runs each plugin's `onShutdown` once, up to the shutdown deadline. */
|
|
164
|
-
stopPlugins: () => Promise<void>;
|
|
165
|
-
/** Aborts `shutdownSignal()` of this copy of the package. */
|
|
166
|
-
abortShutdownSignal: () => void;
|
|
167
|
-
};
|
|
168
|
-
/** Options for {@link createEntry}. */
|
|
169
|
-
type CreateEntryOptions = {
|
|
170
|
-
/** The app from `createServer`. */
|
|
171
|
-
app: AppServer;
|
|
172
|
-
/** The run side of the host adapter, such as `host` from `@ngrok/app-server/node`. */
|
|
173
|
-
host: HostRuntime;
|
|
174
|
-
/** Makes the run side of the framework adapter for a mode. */
|
|
175
|
-
framework: (mode: Mode) => FrameworkRuntime;
|
|
176
|
-
/**
|
|
177
|
-
* The client build, as a file path or a `file:` URL. The entry that the
|
|
178
|
-
* Vite plugin generates sets it.
|
|
179
|
-
* @default the framework's `clientDirectory`
|
|
180
|
-
*/
|
|
181
|
-
clientDirectory?: string;
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* The `appServer` export of a server build: an app from `createServer`, the
|
|
185
|
-
* host, and the framework adapter for each mode. The `appServer` Vite plugin
|
|
186
|
-
* generates this export. Call this for a build without the plugin.
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
|
|
190
|
-
*/
|
|
191
|
-
export declare function createEntry({ app, host, framework, clientDirectory }: CreateEntryOptions): AppServerEntry;
|
|
1
|
+
import { C as SetupInfo, E as ResponseEdge, S as ServerBindings, T as StaticFiles, _ as RequestContext, a as FrameworkRuntime, b as ResponseHeaders, c as HostRuntime, d as ListenerBindings, f as ListenerStartOptions, g as Plugin, h as Mode, i as FileInfo, l as Lifecycle, m as LogSink, n as ByteRange, o as FrameworkRuntimeFactory, p as LogLevel, r as FetchHandler, s as HeaderHook, t as AppServerEnv, u as Listener, v as RequestLogger, w as StartedListener, x as SentResponse, y as RequestStore } from "./types-DLYxYS6M.js";
|
|
2
|
+
import { A as BuildIdOptions, C as SecurityHeadersOptions, D as redirects, E as RedirectRule, M as AccessLogOptions, N as accessLog, O as HealthOptions, S as SecurityHeaderValues, T as securityHeaders, _ as StandardSchemaV1, a as CreateServerOptions, b as requestId, c as createServer, d as assets, f as prerendered, g as RuntimeEnvOptions, h as RuntimeEnv, i as AppServer, j as buildId, k as health, l as defaultPlugins, m as PUBLIC_ENV_SCRIPT_ID, n as CreateEntryOptions, o as DefaultPluginsOptions, p as InferOutput, r as createEntry, s as RunningServer, t as AppServerEntry, u as PrerenderedOptions, v as runtimeEnv, w as contentSecurityPolicy, x as ContentSecurityPolicyOptions, y as RequestIdOptions } from "./entry-CM6Ma-Tv.js";
|
|
3
|
+
import { n as TrailingSlashOptions, r as trailingSlash, t as TrailingSlash } from "./trailing-slash-DX7NB88H.js";
|
|
4
|
+
import { Context, Next } from "hono";
|
|
192
5
|
/** One server-sent event. */
|
|
193
6
|
type ServerSentEvent = {
|
|
194
7
|
data: string;
|
|
@@ -229,10 +42,29 @@ type EventStreamOptions = {
|
|
|
229
42
|
* }
|
|
230
43
|
*/
|
|
231
44
|
export declare function eventStream({ signal, heartbeatMs, headers }: EventStreamOptions, produce: (sink: EventStreamSink) => void | Promise<void>): Response;
|
|
45
|
+
/**
|
|
46
|
+
* Runs `hook` on the response headers after the later stages. In an app
|
|
47
|
+
* server, the hook changes the head once, where the response leaves, so the
|
|
48
|
+
* response needs no copy. That run comes after the code that each stage runs
|
|
49
|
+
* after its `next()`, so a stage can decide there what its hook does. A hook
|
|
50
|
+
* that throws gives a 500. See {@link HeaderHook} for the order of the hooks
|
|
51
|
+
* and the views that also run them.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* const frameOptions: Plugin = {
|
|
55
|
+
* name: "frame-options",
|
|
56
|
+
* middleware: async (c, next) =>
|
|
57
|
+
* withHeaderHook(c, next, (response) => {
|
|
58
|
+
* response.set("X-Frame-Options", "DENY");
|
|
59
|
+
* }),
|
|
60
|
+
* };
|
|
61
|
+
*/
|
|
62
|
+
export declare function withHeaderHook(context: Context<AppServerEnv>, next: Next, hook: HeaderHook): Promise<void>;
|
|
232
63
|
/**
|
|
233
64
|
* A log sink that writes one JSON object per line. Each line has `time`,
|
|
234
65
|
* `level`, `message`, and the flat attributes, which Datadog reads as its
|
|
235
|
-
* standard attributes.
|
|
66
|
+
* standard attributes. The default writes the lines of one event-loop turn
|
|
67
|
+
* to stdout at the end of the turn.
|
|
236
68
|
*
|
|
237
69
|
* @param write - Where each line goes. Defaults to stdout.
|
|
238
70
|
*
|
|
@@ -241,94 +73,60 @@ export declare function eventStream({ signal, heartbeatMs, headers }: EventStrea
|
|
|
241
73
|
* // {"time":"2026-10-28T12:00:00.000Z","level":"info","message":"request","http.status_code":200}
|
|
242
74
|
*/
|
|
243
75
|
export declare function jsonSink(write?: (line: string) => void): LogSink;
|
|
244
|
-
/** Options for {@link
|
|
245
|
-
type
|
|
246
|
-
/**
|
|
247
|
-
|
|
248
|
-
/** The deployed build, such as the image tag. Read it from the runtime env, not the build. */
|
|
249
|
-
value: string;
|
|
76
|
+
/** Options for {@link bodyLimit}. */
|
|
77
|
+
type BodyLimitOptions = {
|
|
78
|
+
/** The largest request body, in bytes. */
|
|
79
|
+
maxBytes: number;
|
|
250
80
|
};
|
|
251
81
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
82
|
+
* Sends a 413 for a request body that is larger than `maxBytes`. A request
|
|
83
|
+
* whose `Content-Length` is too large gets the 413 before the app reads the
|
|
84
|
+
* body, and a request whose `Content-Length` fits goes on unchanged. A
|
|
85
|
+
* streamed body with no `Content-Length` errors when it passes the limit. When the app reads the body before it answers, the response
|
|
86
|
+
* becomes a 413. When the app streams the body into its response, the
|
|
87
|
+
* response stream errors. A `maxBytes` that is not a whole number of 0 or
|
|
88
|
+
* more stops startup.
|
|
89
|
+
*
|
|
90
|
+
* Why not `hono/body-limit`: it reads a streamed body into memory before the
|
|
91
|
+
* next stage runs, so an upload cannot stream.
|
|
255
92
|
*
|
|
256
93
|
* @example
|
|
257
|
-
*
|
|
94
|
+
* createServer({ plugins: [requestId(), accessLog(), bodyLimit({ maxBytes: 1_048_576 })] });
|
|
258
95
|
*/
|
|
259
|
-
export declare function
|
|
260
|
-
type StandardIssue = {
|
|
261
|
-
readonly message: string;
|
|
262
|
-
readonly path?: readonly (PropertyKey | {
|
|
263
|
-
readonly key: PropertyKey;
|
|
264
|
-
})[] | undefined;
|
|
265
|
-
};
|
|
266
|
-
type StandardResult<Output> = {
|
|
267
|
-
readonly value: Output;
|
|
268
|
-
readonly issues?: undefined;
|
|
269
|
-
} | {
|
|
270
|
-
readonly issues: readonly StandardIssue[];
|
|
271
|
-
};
|
|
272
|
-
/** A schema that follows the Standard Schema interface, such as a zod object. */
|
|
273
|
-
type StandardSchemaV1<Input = unknown, Output = Input> = {
|
|
274
|
-
readonly "~standard": {
|
|
275
|
-
readonly version: 1;
|
|
276
|
-
readonly vendor: string;
|
|
277
|
-
readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>;
|
|
278
|
-
readonly types?: {
|
|
279
|
-
readonly input: Input;
|
|
280
|
-
readonly output: Output;
|
|
281
|
-
} | undefined;
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
/** The parsed type of a Standard Schema. */
|
|
285
|
-
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
286
|
-
/** The `id` of the JSON `<script>` that carries the public values into each HTML document. */
|
|
287
|
-
export declare const PUBLIC_ENV_SCRIPT_ID = "app-server-public-env";
|
|
288
|
-
/** Options for {@link runtimeEnv}. */
|
|
289
|
-
type RuntimeEnvOptions = {
|
|
290
|
-
/** @default process.env */
|
|
291
|
-
source?: Readonly<Record<string, string | undefined>>;
|
|
292
|
-
/**
|
|
293
|
-
* Values whose names start with this prefix reach the browser.
|
|
294
|
-
* @default "PUBLIC_"
|
|
295
|
-
*/
|
|
296
|
-
publicPrefix?: string;
|
|
297
|
-
};
|
|
298
|
-
/** The plugin that {@link runtimeEnv} returns, with the parsed values. */
|
|
299
|
-
type RuntimeEnv<Values> = Plugin & {
|
|
300
|
-
/** The parsed values. The first read parses, and a bad value throws. */
|
|
301
|
-
readonly values: Values;
|
|
302
|
-
/** The parsed values whose names start with the public prefix. */
|
|
303
|
-
readonly publicValues: Readonly<Record<string, unknown>>;
|
|
304
|
-
};
|
|
96
|
+
export declare function bodyLimit({ maxBytes }: BodyLimitOptions): Plugin;
|
|
305
97
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* The values whose names start with `PUBLIC_` go into each HTML document,
|
|
311
|
-
* prerendered or rendered, as a JSON `<script id="app-server-public-env">`.
|
|
312
|
-
* So one image serves every environment, and a prerendered page never keeps
|
|
313
|
-
* the values of the build. Put this plugin before the static stages, so it
|
|
314
|
-
* sees the prerendered pages.
|
|
98
|
+
* Sets `X-Robots-Tag: noindex, nofollow` on each response, so a search
|
|
99
|
+
* engine does not index a preview deploy. Turn it on from the environment
|
|
100
|
+
* with the `noindex` option of `defaultPlugins()`, which puts it before the
|
|
101
|
+
* static stages, so it also sees prerendered pages.
|
|
315
102
|
*
|
|
316
103
|
* @example
|
|
317
|
-
*
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
104
|
+
* defaultPlugins({ noindex: process.env.PREVIEW === "1" });
|
|
105
|
+
*/
|
|
106
|
+
export declare function noindex(): Plugin;
|
|
107
|
+
/**
|
|
108
|
+
* Sets `Cache-Control: private, no-cache` on each HTML document and each
|
|
109
|
+
* framework data response, such as a React Router `.data` request, that has
|
|
110
|
+
* no `Cache-Control`. A shared cache then never keeps a page or loader data
|
|
111
|
+
* that the server rendered for one user. A response with its own
|
|
112
|
+
* `Cache-Control` keeps it. A resource route that sends per-user JSON sets
|
|
113
|
+
* its own `Cache-Control`.
|
|
321
114
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
115
|
+
* Put it after the static stages, so it sees only the responses of the app's
|
|
116
|
+
* routes and the framework. `defaultPlugins()` puts it last.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* createServer({ plugins: [requestId(), accessLog(), assets(), prerendered(), privateDocuments()] });
|
|
324
120
|
*/
|
|
325
|
-
export declare function
|
|
121
|
+
export declare function privateDocuments(): Plugin;
|
|
326
122
|
/**
|
|
327
123
|
* Gzips text responses and flushes after each chunk, so a streamed page shell
|
|
328
|
-
* or a server-sent event reaches the client at once.
|
|
124
|
+
* or a server-sent event reaches the client at once. Chunks that the body has
|
|
125
|
+
* queued together are one chunk, up to 16 KiB. `hono/compress` holds a
|
|
329
126
|
* stream until it ends. Skips a response that is already encoded, a partial
|
|
330
|
-
* response,
|
|
331
|
-
*
|
|
127
|
+
* response, one marked `no-transform`, and one whose `Content-Length` is
|
|
128
|
+
* under 1 KiB. It adds `Accept-Encoding` to the `Vary` of each response that
|
|
129
|
+
* it can gzip. The host gives the gzip stream. On a host with none, the
|
|
332
130
|
* plugin does nothing.
|
|
333
131
|
*
|
|
334
132
|
* @example
|
|
@@ -336,7 +134,39 @@ export declare function runtimeEnv<Schema extends StandardSchemaV1>(schema: Sche
|
|
|
336
134
|
*/
|
|
337
135
|
export declare function streamingCompress(): Plugin;
|
|
338
136
|
/**
|
|
339
|
-
*
|
|
137
|
+
* Whether a request asks for markdown before HTML, per
|
|
138
|
+
* https://acceptmarkdown.com. Use it to choose between the HTML and the
|
|
139
|
+
* markdown answer for one URL.
|
|
140
|
+
*
|
|
141
|
+
* The rules:
|
|
142
|
+
*
|
|
143
|
+
* - Only an explicit `text/markdown` range counts for markdown. A wildcard,
|
|
144
|
+
* such as `*\/*` or `text/*`, never selects markdown, so a browser and a
|
|
145
|
+
* client with no `Accept` get HTML.
|
|
146
|
+
* - `text/markdown;q=0` refuses markdown.
|
|
147
|
+
* - The `q` of markdown must be equal to or higher than the `q` of HTML. The
|
|
148
|
+
* `q` of HTML comes from the most specific range that matches it:
|
|
149
|
+
* `text/html`, then `text/*`, then `*\/*`. A tie selects markdown, because
|
|
150
|
+
* the client named it.
|
|
151
|
+
* - Both answers are UTF-8. A range with `charset=utf-8` is more specific
|
|
152
|
+
* than a range with no charset, and a range with another charset does not
|
|
153
|
+
* match. Other parameters, such as `variant`, do not change the match.
|
|
154
|
+
* - Media types and parameter names are not case-sensitive. A quoted
|
|
155
|
+
* parameter value can hold a `,` or a `;`.
|
|
156
|
+
*
|
|
157
|
+
* When the answer for a URL depends on this function, send `Vary: Accept` on
|
|
158
|
+
* both the HTML and the markdown answer. Else a shared cache can give the
|
|
159
|
+
* markdown to a browser.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* prefersMarkdown(new Request("https://example.com/", { headers: { Accept: "text/markdown" } }));
|
|
163
|
+
* // => true
|
|
164
|
+
* prefersMarkdown(new Request("https://example.com/", { headers: { Accept: "text/html, text/markdown;q=0.5" } }));
|
|
165
|
+
* // => false
|
|
166
|
+
*/
|
|
167
|
+
export declare function prefersMarkdown(request: Request): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* The request ID, logger, and CSP nonce of the request that runs. It gives `undefined`
|
|
340
170
|
* outside a server request, such as in a prerender pass, or on a host with no
|
|
341
171
|
* request storage.
|
|
342
172
|
*
|
|
@@ -357,5 +187,5 @@ export declare function requestContext(): RequestContext | undefined;
|
|
|
357
187
|
* shutdownSignal().addEventListener("abort", () => clearInterval(timer), { once: true });
|
|
358
188
|
*/
|
|
359
189
|
export declare function shutdownSignal(): AbortSignal;
|
|
360
|
-
export type
|
|
190
|
+
export { type AccessLogOptions, type AppServer, type AppServerEntry, type AppServerEnv, type BodyLimitOptions, type BuildIdOptions, type ByteRange, type ContentSecurityPolicyOptions, type CreateEntryOptions, type CreateServerOptions, type DefaultPluginsOptions, type EventStreamOptions, type EventStreamSink, type FetchHandler, type FileInfo, type FrameworkRuntime, type FrameworkRuntimeFactory, type HeaderHook, type HealthOptions, type HostRuntime, type InferOutput, type Lifecycle, type Listener, type ListenerBindings, type ListenerStartOptions, type LogLevel, type LogSink, type Mode, PUBLIC_ENV_SCRIPT_ID, type Plugin, type PrerenderedOptions, type RedirectRule, type RequestContext, type RequestIdOptions, type RequestLogger, type RequestStore, ResponseEdge, type ResponseHeaders, type RunningServer, type RuntimeEnv, type RuntimeEnvOptions, type SecurityHeaderValues, type SecurityHeadersOptions, type SentResponse, type ServerBindings, type ServerSentEvent, type SetupInfo, type StandardSchemaV1, type StartedListener, type StaticFiles, type TrailingSlash, type TrailingSlashOptions, accessLog, assets, buildId, contentSecurityPolicy, createEntry, createServer, defaultPlugins, health, prerendered, redirects, requestId, runtimeEnv, securityHeaders, trailingSlash };
|
|
361
191
|
//# sourceMappingURL=index.d.ts.map
|