@ngrok/app-server 0.1.1 → 0.3.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 (105) hide show
  1. package/README.md +659 -70
  2. package/dist/build-id-C6sYO9Yp.js +126 -0
  3. package/dist/build-id-C6sYO9Yp.js.map +1 -0
  4. package/dist/build-manifest-UDNk81Ce.js +63 -0
  5. package/dist/build-manifest-UDNk81Ce.js.map +1 -0
  6. package/dist/{bun-DCGnDEPn.js → bun-BCz6K_Xv.js} +12 -8
  7. package/dist/bun-BCz6K_Xv.js.map +1 -0
  8. package/dist/cli.js +47 -27
  9. package/dist/cli.js.map +1 -1
  10. package/dist/client.d.ts +141 -0
  11. package/dist/client.js +326 -0
  12. package/dist/client.js.map +1 -0
  13. package/dist/compression-7_gToa8R.js +97 -0
  14. package/dist/compression-7_gToa8R.js.map +1 -0
  15. package/dist/create-server-iE1-s6Bi.js +1409 -0
  16. package/dist/create-server-iE1-s6Bi.js.map +1 -0
  17. package/dist/{deno-BnMfk2n1.js → deno-aqhikNMG.js} +5 -5
  18. package/dist/deno-aqhikNMG.js.map +1 -0
  19. package/dist/entry-DZ3qo7qF.js +116 -0
  20. package/dist/entry-DZ3qo7qF.js.map +1 -0
  21. package/dist/entry-DmJEqVfd.d.ts +622 -0
  22. package/dist/gzip-Doi4wqjX.js +294 -0
  23. package/dist/gzip-Doi4wqjX.js.map +1 -0
  24. package/dist/header-hook-Vzw9J9BY.js +159 -0
  25. package/dist/header-hook-Vzw9J9BY.js.map +1 -0
  26. package/dist/index-Bo5G9LuQ.d.ts +127 -0
  27. package/dist/index.d.ts +110 -95
  28. package/dist/index.js +56 -57
  29. package/dist/index.js.map +1 -1
  30. package/dist/{listen-options-DHWmSWGi.js → listen-options-7TaXjyrk.js} +2 -2
  31. package/dist/listen-options-7TaXjyrk.js.map +1 -0
  32. package/dist/load-entry-AfYS_zS9.js +37 -0
  33. package/dist/load-entry-AfYS_zS9.js.map +1 -0
  34. package/dist/log-BP6xXXZl.js +122 -0
  35. package/dist/log-BP6xXXZl.js.map +1 -0
  36. package/dist/node-BFH82eeL.js +333 -0
  37. package/dist/node-BFH82eeL.js.map +1 -0
  38. package/dist/node-tBVQPjQv.js +41 -0
  39. package/dist/node-tBVQPjQv.js.map +1 -0
  40. package/dist/node-vite.d.ts +11 -0
  41. package/dist/node-vite.js +3 -0
  42. package/dist/node.d.ts +86 -0
  43. package/dist/node.js +4 -0
  44. package/dist/react-router-vite.d.ts +10 -0
  45. package/dist/react-router-vite.js +3 -0
  46. package/dist/react-router.d.ts +11 -24
  47. package/dist/react-router.js +21 -30
  48. package/dist/react-router.js.map +1 -1
  49. package/dist/request-context-BtQ87VYb.js +40 -0
  50. package/dist/request-context-BtQ87VYb.js.map +1 -0
  51. package/dist/response-edge-Bc1-C_Cx.js +327 -0
  52. package/dist/response-edge-Bc1-C_Cx.js.map +1 -0
  53. package/dist/response-writer-B7FoJjEE.js +289 -0
  54. package/dist/response-writer-B7FoJjEE.js.map +1 -0
  55. package/dist/script-hashes-hqUk6kG7.js +53 -0
  56. package/dist/script-hashes-hqUk6kG7.js.map +1 -0
  57. package/dist/serve-CDNgThjk.js +29 -0
  58. package/dist/serve-CDNgThjk.js.map +1 -0
  59. package/dist/{start-BVMb8Pyt.js → start-TLIprD74.js} +96 -81
  60. package/dist/start-TLIprD74.js.map +1 -0
  61. package/dist/static-files-Beju9riB.js +302 -0
  62. package/dist/static-files-Beju9riB.js.map +1 -0
  63. package/dist/tanstack-start-vite.d.ts +12 -0
  64. package/dist/tanstack-start-vite.js +3 -0
  65. package/dist/tanstack-start.d.ts +34 -0
  66. package/dist/tanstack-start.js +41 -0
  67. package/dist/tanstack-start.js.map +1 -0
  68. package/dist/{tcp-Dau_IONd.js → tcp-Dd1Mt6sN.js} +8 -7
  69. package/dist/tcp-Dd1Mt6sN.js.map +1 -0
  70. package/dist/trailing-slash-DX7NB88H.d.ts +36 -0
  71. package/dist/types-DLYxYS6M.d.ts +392 -0
  72. package/dist/vercel-vite.d.ts +35 -0
  73. package/dist/vercel-vite.js +142 -0
  74. package/dist/vercel-vite.js.map +1 -0
  75. package/dist/vercel.d.ts +35 -0
  76. package/dist/vercel.js +89 -0
  77. package/dist/vercel.js.map +1 -0
  78. package/dist/vite-B-GfswoH.js +22 -0
  79. package/dist/vite-B-GfswoH.js.map +1 -0
  80. package/dist/vite-D4hfj3ph.js +19 -0
  81. package/dist/vite-D4hfj3ph.js.map +1 -0
  82. package/dist/vite-DyrhyKEr.js +25 -0
  83. package/dist/vite-DyrhyKEr.js.map +1 -0
  84. package/dist/vite-iioAoxSt.js +752 -0
  85. package/dist/vite-iioAoxSt.js.map +1 -0
  86. package/dist/vite.d.ts +2 -27
  87. package/dist/vite.js +2 -2
  88. package/package.json +50 -4
  89. package/dist/bun-DCGnDEPn.js.map +0 -1
  90. package/dist/captured-headers-ewL_t3MQ.js +0 -48
  91. package/dist/captured-headers-ewL_t3MQ.js.map +0 -1
  92. package/dist/deno-BnMfk2n1.js.map +0 -1
  93. package/dist/entry-CIpwaayZ.d.ts +0 -293
  94. package/dist/entry-ChjmFwX5.js +0 -755
  95. package/dist/entry-ChjmFwX5.js.map +0 -1
  96. package/dist/listen-options-DHWmSWGi.js.map +0 -1
  97. package/dist/node-2wWBMFeO.js +0 -3
  98. package/dist/node-79my3Uix.js +0 -58
  99. package/dist/node-79my3Uix.js.map +0 -1
  100. package/dist/serve-ByeedcRB.js +0 -16
  101. package/dist/serve-ByeedcRB.js.map +0 -1
  102. package/dist/start-BVMb8Pyt.js.map +0 -1
  103. package/dist/tcp-Dau_IONd.js.map +0 -1
  104. package/dist/vite-CrNqpoeK.js +0 -102
  105. package/dist/vite-CrNqpoeK.js.map +0 -1
@@ -1,293 +0,0 @@
1
- import { Context, Hono, MiddlewareHandler } from "hono";
2
- import { IncomingMessage, ServerResponse } from "node:http";
3
- /** A log level the server writes. */
4
- type LogLevel = "debug" | "info" | "warn" | "error";
5
- /**
6
- * Where the server writes log lines. Pass the app's own formatter, or use
7
- * {@link jsonSink}. Attribute names are flat and dotted, such as `http.method`.
8
- */
9
- type LogSink = {
10
- log: (level: LogLevel, message: string, attributes: Readonly<Record<string, unknown>>) => void;
11
- };
12
- /** The logger for one request. Each line carries the request ID, method, and path. */
13
- type RequestLogger = Record<LogLevel, (message: string, attributes?: Readonly<Record<string, unknown>>) => void>;
14
- /** The framework that answers each request that no plugin or route answers. */
15
- type FrameworkAdapter = {
16
- /** Renders one request. */
17
- fetch: (request: Request, context: Context<AppServerEnv>) => Promise<Response>;
18
- /** The absolute path of the client build, such as `<root>/build/client`. */
19
- clientDirectory: string;
20
- /** The URL paths that the build prerendered. */
21
- prerenderedPaths: readonly string[];
22
- };
23
- /** What a listener passes to the app with each request. */
24
- type ListenerBindings = {
25
- /** The client's IP address, when the runtime knows it. */
26
- remoteAddress?: string;
27
- /** Node's request, on a `node:http` listener only. */
28
- incoming?: IncomingMessage;
29
- /** Node's response, on a `node:http` listener only. */
30
- outgoing?: ServerResponse;
31
- };
32
- /** The Hono bindings of an app server: the listener's values and the framework. */
33
- type ServerBindings = ListenerBindings & {
34
- framework: FrameworkAdapter;
35
- };
36
- /** The Hono environment of an app server. */
37
- type AppServerEnv = {
38
- Bindings: ServerBindings;
39
- Variables: {
40
- /** The request ID, set by the `requestId` plugin. */
41
- requestId?: string;
42
- logger: RequestLogger;
43
- /**
44
- * The `etagPart` of each plugin that the request passed, in order. The
45
- * static stages add them to each file's ETag. The server sets this list.
46
- */
47
- etagParts?: readonly string[];
48
- };
49
- };
50
- /** The request handler that a listener calls. */
51
- type FetchHandler = (request: Request, bindings: ListenerBindings) => Response | Promise<Response>;
52
- /** A Connect middleware, such as `vite.middlewares`. */
53
- type NodeMiddleware = (request: IncomingMessage, response: ServerResponse, next: (error?: unknown) => void) => void;
54
- /** What a plugin learns at startup, before the first request. */
55
- type SetupInfo = {
56
- /** The absolute path of the client build. */
57
- clientDirectory: string;
58
- /** The URL paths that the build prerendered. */
59
- prerenderedPaths: readonly string[];
60
- logger: LogSink;
61
- } & ({
62
- mode: "production";
63
- } | {
64
- mode: "development";
65
- /** Vite's middleware stack, which serves source modules and HMR. */
66
- viteMiddleware: NodeMiddleware;
67
- });
68
- /**
69
- * One step of the request pipeline. Plugins run in list order, so the order is
70
- * the contract.
71
- *
72
- * @example
73
- * const livez: Plugin = {
74
- * name: "livez",
75
- * middleware: async (c, next) => (c.req.path === "/livez" ? c.text("ok") : next()),
76
- * };
77
- */
78
- type Plugin = {
79
- /** A name for logs and errors. */
80
- name: string;
81
- /** The Hono middleware for this step. */
82
- middleware?: MiddlewareHandler<AppServerEnv>;
83
- /** Runs once before the server takes requests. A thrown error stops startup. */
84
- setup?: (info: SetupInfo) => void | Promise<void>;
85
- /** Runs at shutdown while the listeners drain. The server stops waiting for it at the drain deadline. */
86
- onShutdown?: () => Promise<void>;
87
- /**
88
- * A value that this plugin's changes to a response depend on, such as the
89
- * env values it writes into each document. The server adds it to the ETag
90
- * of each static file that the request reaches after this plugin, so a 304
91
- * never keeps a response made with an old value. Return `undefined` when
92
- * the plugin changes nothing.
93
- */
94
- etagPart?: () => string | undefined;
95
- };
96
- /** A running listener. */
97
- type StartedListener = {
98
- /** The URL the listener answers on. */
99
- url: string;
100
- /**
101
- * Stops new connections and waits for open requests. At the deadline, it
102
- * closes the connections that are still open.
103
- */
104
- stop: (options: {
105
- deadlineMs: number;
106
- }) => Promise<void>;
107
- };
108
- /**
109
- * How the server receives connections, separate from the request pipeline.
110
- *
111
- * @example
112
- * createServer({ listeners: [tcp({ port: 8080 })] });
113
- */
114
- type Listener = {
115
- /** A name for logs. */
116
- name: string;
117
- start: (fetch: FetchHandler) => Promise<StartedListener>;
118
- };
119
- /** Options for {@link accessLog}. */
120
- type AccessLogOptions = {
121
- /**
122
- * Replace each query value with `REDACTED`, so a single-use code in a URL
123
- * never reaches a log.
124
- * @default true
125
- */
126
- redactQuery?: boolean;
127
- };
128
- /**
129
- * One log line per request, static hits included, with Datadog standard
130
- * attribute names. The line goes out when the body ends or the client
131
- * disconnects, so a streamed response logs its full duration and size.
132
- *
133
- * @example
134
- * createServer({ plugins: [requestId(), accessLog({ redactQuery: false })] });
135
- * // {"level":"info","message":"request","http.status_code":200,"network.bytes_written":5120,"duration":1830000,...}
136
- */
137
- declare function accessLog({ redactQuery }?: AccessLogOptions): Plugin;
138
- /** Options for {@link requestId}. */
139
- type RequestIdOptions = {
140
- /** @default "X-Request-Id" */
141
- headerName?: string;
142
- };
143
- /**
144
- * Gives each request an ID: a valid incoming header (up to 255 word
145
- * characters, `-`, and `=`), else a new UUID. The ID goes on the response, on
146
- * every log line, and into the framework's context.
147
- *
148
- * @example
149
- * const app = createServer({ plugins: [requestId()] });
150
- * const response = await app.request("/", { headers: { "X-Request-Id": "abc-123" } });
151
- * response.headers.get("X-Request-Id"); // => "abc-123"
152
- */
153
- declare function requestId({ headerName }?: RequestIdOptions): Plugin;
154
- /**
155
- * Serves the hashed files under `/assets/` with a one-year immutable cache.
156
- * A missing asset gets a plain 404, not a rendered page. In development,
157
- * Vite serves the source modules, the HMR client, and the CSS here instead.
158
- *
159
- * @example
160
- * createServer({ plugins: [requestId(), accessLog(), streamingCompress(), assets(), prerendered()] });
161
- */
162
- declare function assets(): Plugin;
163
- /** Options for {@link prerendered}. */
164
- type PrerenderedOptions = {
165
- /**
166
- * Extra headers for a served file, by its URL path. They replace the
167
- * headers captured at build time.
168
- */
169
- headers?: (path: string, context: Context<AppServerEnv>) => Readonly<Record<string, string>> | undefined;
170
- /**
171
- * Maps a request path to the URL path of the file to serve, for content
172
- * negotiation. Return the path unchanged to serve the usual file. The
173
- * returned path follows the rules of a request path: one URL for each
174
- * file, no dotfiles, and nothing outside the client build. When the
175
- * answer depends on a request header, add a `Vary` for it in a plugin.
176
- */
177
- rewrite?: (path: string, context: Context<AppServerEnv>) => string;
178
- };
179
- /**
180
- * Serves the client build: prerendered pages at their own URL with a 200 and
181
- * no trailing-slash redirect, plus every other file in it. Each response gets
182
- * the headers its loader sent at build time (the `serverEntry` Vite plugin
183
- * captures them), an ETag, and a 304 for a matching `If-None-Match`. A path
184
- * with no file goes on to the framework. Off in development.
185
- *
186
- * At startup, it warns about each prerendered path that has no file.
187
- *
188
- * @example
189
- * prerendered({
190
- * headers: (path) => (path.startsWith("/api/") ? { "Access-Control-Allow-Origin": "*" } : undefined),
191
- * });
192
- */
193
- declare function prerendered(options?: PrerenderedOptions): Plugin;
194
- /** A Hono app from {@link createServer}. Add routes to it before you export it. */
195
- type AppServer = Hono<AppServerEnv>;
196
- /** A server that listens. */
197
- type RunningServer = {
198
- /** The URL of each listener. */
199
- urls: readonly string[];
200
- /**
201
- * Aborts `shutdownSignal()`, then runs each plugin's `onShutdown` while the
202
- * listeners stop and drain open requests. Both stop at the deadline.
203
- */
204
- shutdown: () => Promise<void>;
205
- };
206
- /** Options for {@link defaultPlugins}. */
207
- type DefaultPluginsOptions = {
208
- requestId?: RequestIdOptions;
209
- accessLog?: AccessLogOptions;
210
- prerendered?: PrerenderedOptions;
211
- /**
212
- * Plugins that go after compression and before the static stages, so they
213
- * see every response, prerendered pages included. `runtimeEnv` and
214
- * `buildId` go here.
215
- */
216
- beforeStatic?: readonly Plugin[];
217
- };
218
- /**
219
- * The default pipeline, in order: `requestId`, `accessLog`,
220
- * `streamingCompress`, the `beforeStatic` plugins, `assets`, and
221
- * `prerendered`. It is a plain array, so an app can filter it or splice into it.
222
- *
223
- * @example
224
- * createServer({ plugins: defaultPlugins({ accessLog: { redactQuery: false }, beforeStatic: [env] }) });
225
- */
226
- declare function defaultPlugins(options?: DefaultPluginsOptions): Plugin[];
227
- /** Options for {@link createServer}. */
228
- type CreateServerOptions = {
229
- /** @default defaultPlugins() */
230
- plugins?: readonly Plugin[];
231
- /** @default jsonSink() */
232
- logger?: LogSink;
233
- /** @default [tcp()] */
234
- listeners?: readonly Listener[];
235
- /**
236
- * Read the request scheme from `X-Forwarded-Proto`. Set it only behind a
237
- * proxy that overwrites that header, else a client can spoof it.
238
- * @default false
239
- */
240
- trustForwardedProto?: boolean;
241
- /**
242
- * How long open requests get to finish after a stop signal.
243
- * @default 10000
244
- */
245
- shutdownDeadlineMs?: number;
246
- };
247
- /**
248
- * Builds an app server: a Hono app that runs the plugins in list order, then
249
- * the app's own routes, then the framework. It does not listen; the
250
- * `app-server` CLI starts it.
251
- *
252
- * @example
253
- * // server.ts
254
- * const app = createServer({ logger: slogSink, plugins: defaultPlugins({ beforeStatic: [env] }) });
255
- * app.get("/livez", (c) => c.text("ok"));
256
- * export default app;
257
- */
258
- declare function createServer$1({ plugins, logger, listeners, trustForwardedProto, shutdownDeadlineMs }?: CreateServerOptions): AppServer;
259
- /** The version of the contract between the CLI and the `appServer` export of a build. */
260
- declare const ENTRY_PROTOCOL = 1;
261
- /**
262
- * What a server build exports as `appServer`. The CLI calls it, so the copy
263
- * of this package in the build runs the server, and the CLI's copy runs
264
- * nothing.
265
- */
266
- type AppServerEntry = {
267
- /** The CLI refuses an entry with another version. */
268
- protocol: typeof ENTRY_PROTOCOL;
269
- /** The app. Two entries with the same app share its plugins. */
270
- app: AppServer;
271
- /** Production: runs each plugin's `setup`, listens, and shuts down on `SIGTERM` or `SIGINT`. */
272
- start: () => Promise<void>;
273
- /** Development: answers one request with Vite's middleware inside the pipeline. */
274
- fetchDev: (request: Request, bindings: ListenerBindings, viteMiddleware: NodeMiddleware) => Promise<Response>;
275
- /** Runs each plugin's `onShutdown` once, up to the shutdown deadline. */
276
- stopPlugins: () => Promise<void>;
277
- /** Aborts `shutdownSignal()` of this copy of the package. */
278
- abortShutdownSignal: () => void;
279
- };
280
- /**
281
- * The `appServer` export of a server build: an app from `createServer` and
282
- * the framework adapter for each mode. The `serverEntry` Vite plugin makes
283
- * this export for a React Router build. Call this for another framework.
284
- *
285
- * @example
286
- * export const appServer = createEntry({ app, framework: (mode) => myAdapter(build, mode) });
287
- */
288
- declare function createEntry({ app, framework }: {
289
- app: AppServer;
290
- framework: (mode: SetupInfo["mode"]) => FrameworkAdapter;
291
- }): AppServerEntry;
292
- export { NodeMiddleware as C, SetupInfo as D, ServerBindings as E, StartedListener as O, LogSink as S, RequestLogger as T, FetchHandler as _, DefaultPluginsOptions as a, ListenerBindings as b, defaultPlugins as c, prerendered as d, RequestIdOptions as f, AppServerEnv as g, accessLog as h, CreateServerOptions as i, PrerenderedOptions as l, AccessLogOptions as m, createEntry as n, RunningServer as o, requestId as p, AppServer as r, createServer$1 as s, AppServerEntry as t, assets as u, FrameworkAdapter as v, Plugin as w, LogLevel as x, Listener as y };
293
- //# sourceMappingURL=entry-CIpwaayZ.d.ts.map