@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
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { Context, MiddlewareHandler } from "hono";
|
|
2
|
+
/**
|
|
3
|
+
* What the server and a listener that writes each response itself share for
|
|
4
|
+
* one request. The listener makes one for each request and gives it as the
|
|
5
|
+
* `edge` binding. The server then runs the header hooks on a list of the
|
|
6
|
+
* headers, so it copies no response for them. The listener:
|
|
7
|
+
*
|
|
8
|
+
* - writes {@link ResponseEdge.headersFor} in place of the headers of the response
|
|
9
|
+
* - adds each body byte that it writes to {@link ResponseEdge.bytes}
|
|
10
|
+
* - gives an error that stops the response to {@link ResponseEdge.fail}
|
|
11
|
+
* - calls {@link ResponseEdge.close} once, when the response ends or its client goes away
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const edge = new ResponseEdge();
|
|
15
|
+
* const response = await fetch(request, { remoteAddress, edge });
|
|
16
|
+
* outgoing.writeHead(response.status, edge.headersFor(response) ?? [...response.headers].flat());
|
|
17
|
+
*/
|
|
18
|
+
declare class ResponseEdge {
|
|
19
|
+
#private;
|
|
20
|
+
/** The body bytes that the listener gave to its socket. */
|
|
21
|
+
bytes: number;
|
|
22
|
+
/**
|
|
23
|
+
* Gives the edge to the request of `logger`, and gives `true`, the first
|
|
24
|
+
* time only. The server calls it when a request starts. Why once: a
|
|
25
|
+
* request that the app sends through itself again with the same bindings
|
|
26
|
+
* must change its own response.
|
|
27
|
+
*/
|
|
28
|
+
claim(logger: RequestLogger): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Keeps `headers`, the headers of the response after each header hook, and
|
|
31
|
+
* `base`, its headers before the hooks. The server calls it.
|
|
32
|
+
*/
|
|
33
|
+
useHeaders(base: readonly string[], headers: string[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* The headers to write for `response`: lowercase names and their values in
|
|
36
|
+
* turn, as Node's `writeHead` takes them. They are the headers after the
|
|
37
|
+
* hooks, with each change that the headers of `response` have from the
|
|
38
|
+
* response that the hooks ran on. Why: Hono answers HEAD with a copy that
|
|
39
|
+
* has no body, and a wrapper of the app's `fetch` can change the headers or
|
|
40
|
+
* return a copy. It gives `undefined` when the server kept no headers.
|
|
41
|
+
*/
|
|
42
|
+
headersFor(response: Response): string[] | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Calls `report` once, when the response ends or its client goes away. It
|
|
45
|
+
* calls it at once when that happened already. A throw from `report` never
|
|
46
|
+
* reaches the listener.
|
|
47
|
+
*/
|
|
48
|
+
onSent(report: (sent: SentResponse) => void): void;
|
|
49
|
+
/** Logs `error`, which stopped the response, with the logger of the request. */
|
|
50
|
+
fail(error: unknown): void;
|
|
51
|
+
/**
|
|
52
|
+
* Reports what went out, once: the status and the headers that the
|
|
53
|
+
* listener sent, the bytes, and whether the body stopped before its end.
|
|
54
|
+
* `head` is the flat list that the listener gave `writeHead`.
|
|
55
|
+
*/
|
|
56
|
+
close(status: number, aborted: boolean, head: string[]): void;
|
|
57
|
+
}
|
|
58
|
+
/** A log level the server writes. */
|
|
59
|
+
type LogLevel = "debug" | "info" | "warn" | "error";
|
|
60
|
+
/**
|
|
61
|
+
* Where the server writes log lines. Pass the app's own formatter, or use
|
|
62
|
+
* {@link jsonSink}. Attribute names are flat and dotted, such as `http.method`.
|
|
63
|
+
*/
|
|
64
|
+
type LogSink = {
|
|
65
|
+
log: (level: LogLevel, message: string, attributes: Readonly<Record<string, unknown>>) => void;
|
|
66
|
+
};
|
|
67
|
+
/** The logger for one request. Each line carries the request ID, method, and path. */
|
|
68
|
+
type RequestLogger = Record<LogLevel, (message: string, attributes?: Readonly<Record<string, unknown>>) => void>;
|
|
69
|
+
/** What {@link requestContext} gives for the request that runs. */
|
|
70
|
+
type RequestContext = {
|
|
71
|
+
/** The request ID, when the `requestId` plugin runs. */
|
|
72
|
+
requestId: string | undefined;
|
|
73
|
+
/** The request's logger. Its lines carry the request ID. */
|
|
74
|
+
logger: RequestLogger;
|
|
75
|
+
/** The nonce for the request's inline scripts, when the `contentSecurityPolicy` plugin runs. */
|
|
76
|
+
cspNonce: string | undefined;
|
|
77
|
+
/** The client's IP address, from `X-Forwarded-For` when `trustedProxyHops` is set, else from the socket. */
|
|
78
|
+
clientAddress: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
/** The server mode. */
|
|
81
|
+
type Mode = "production" | "development";
|
|
82
|
+
/**
|
|
83
|
+
* The run side of a framework adapter: the framework that answers each
|
|
84
|
+
* request that no plugin or route answers.
|
|
85
|
+
*/
|
|
86
|
+
type FrameworkRuntime = {
|
|
87
|
+
/** A name for logs and errors. */
|
|
88
|
+
name: string;
|
|
89
|
+
/** Renders one request. */
|
|
90
|
+
fetch: (request: Request, context: Context<AppServerEnv>) => Promise<Response>;
|
|
91
|
+
/**
|
|
92
|
+
* The client build, when the framework knows it. The entry that the Vite
|
|
93
|
+
* plugin generates gives it instead.
|
|
94
|
+
*/
|
|
95
|
+
clientDirectory?: string;
|
|
96
|
+
/**
|
|
97
|
+
* The URL paths that the build prerenders, when the framework knows them.
|
|
98
|
+
* Else production reads the paths that the Vite plugin captured, and
|
|
99
|
+
* development has none to read.
|
|
100
|
+
*/
|
|
101
|
+
prerenderedPaths?: readonly string[];
|
|
102
|
+
/** Whether a URL path is a data request, such as a React Router `.data` file. */
|
|
103
|
+
isDataRequest?: (path: string) => boolean;
|
|
104
|
+
/** Content types that `mime` does not know, by file extension, such as `{ ".data": "text/x-script" }`. */
|
|
105
|
+
contentTypes?: Readonly<Record<string, string>>;
|
|
106
|
+
};
|
|
107
|
+
/** Makes the run side of a framework adapter from the framework's server module. */
|
|
108
|
+
type FrameworkRuntimeFactory = (serverModule: unknown, info: {
|
|
109
|
+
mode: Mode;
|
|
110
|
+
}) => FrameworkRuntime;
|
|
111
|
+
/** What a host knows about a file under the client build. */
|
|
112
|
+
type FileInfo = {
|
|
113
|
+
kind: "file" | "directory";
|
|
114
|
+
/** The size in bytes. */
|
|
115
|
+
size: number;
|
|
116
|
+
mtimeMs: number;
|
|
117
|
+
};
|
|
118
|
+
/** A range of bytes in a file. `start` and `end` are both inclusive. */
|
|
119
|
+
type ByteRange = {
|
|
120
|
+
start: number;
|
|
121
|
+
end: number;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* The files of the client build. Each path is a URL path that the static
|
|
125
|
+
* stages checked: it starts with `/`, and it has no `..`, no `//`, and no
|
|
126
|
+
* `\`.
|
|
127
|
+
*/
|
|
128
|
+
type StaticFiles = {
|
|
129
|
+
/** What is at `path`, or `undefined` when nothing is there. */
|
|
130
|
+
stat: (path: string) => Promise<FileInfo | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* The bytes of the file at `path`. With `range`, only the bytes from
|
|
133
|
+
* `start` to `end`, both inclusive. A host must honor `range`, because the
|
|
134
|
+
* static stages answer a `Range` request with these bytes. Open the file on
|
|
135
|
+
* the first read. Why: a stage can drop a response that no one reads.
|
|
136
|
+
*/
|
|
137
|
+
open: (path: string, range?: ByteRange) => Promise<ReadableStream<Uint8Array>>;
|
|
138
|
+
/**
|
|
139
|
+
* A copy whose `stat` answers from a list of the files that it reads once.
|
|
140
|
+
* The production server uses it, because the client build does not change
|
|
141
|
+
* while the server runs. Without it, each lookup calls `stat`.
|
|
142
|
+
*/
|
|
143
|
+
snapshot?: () => Promise<StaticFiles>;
|
|
144
|
+
};
|
|
145
|
+
/** Request-scoped storage, such as `AsyncLocalStorage`. */
|
|
146
|
+
type RequestStore = {
|
|
147
|
+
/** Runs `work` with `value` as the stored value. */
|
|
148
|
+
run: <Result>(value: Context<AppServerEnv>, work: () => Result) => Result;
|
|
149
|
+
/** The stored value of the request that runs, else `undefined`. */
|
|
150
|
+
get: () => Context<AppServerEnv> | undefined;
|
|
151
|
+
};
|
|
152
|
+
/** What went out for a response, when it ends or its client goes away. */
|
|
153
|
+
type SentResponse = {
|
|
154
|
+
/**
|
|
155
|
+
* The status that went out. It differs from the status of the response
|
|
156
|
+
* when a listener could not send the response, such as a 500 for a header
|
|
157
|
+
* value that it cannot write.
|
|
158
|
+
*/
|
|
159
|
+
status: number;
|
|
160
|
+
/**
|
|
161
|
+
* The headers that went out with `status`, after each header hook. Read
|
|
162
|
+
* them here, not from `c.res`, which can lack the changes of the hooks: on
|
|
163
|
+
* Node.js and Vercel the hooks change the list that the listener writes,
|
|
164
|
+
* and Bun empties the headers of a response that it sent.
|
|
165
|
+
*/
|
|
166
|
+
headers: Pick<ResponseHeaders, "get" | "has">;
|
|
167
|
+
/**
|
|
168
|
+
* The body bytes that went out, after compression. When `aborted` is
|
|
169
|
+
* true, the client can have got fewer.
|
|
170
|
+
*/
|
|
171
|
+
bytes: number;
|
|
172
|
+
/** Whether the body stopped before its end, such as when the client went away or the body failed. */
|
|
173
|
+
aborted: boolean;
|
|
174
|
+
};
|
|
175
|
+
/** How a long-lived host stops. A serverless host has none. */
|
|
176
|
+
type Lifecycle = {
|
|
177
|
+
/**
|
|
178
|
+
* Calls `stop` once when the host must stop, such as on `SIGTERM`. The host
|
|
179
|
+
* exits when `stop` settles.
|
|
180
|
+
*/
|
|
181
|
+
onStop: (stop: () => Promise<void>) => void;
|
|
182
|
+
};
|
|
183
|
+
/** The run side of a host adapter: where the server runs. */
|
|
184
|
+
type HostRuntime = {
|
|
185
|
+
/** A name for logs and errors. */
|
|
186
|
+
name: string;
|
|
187
|
+
/** The files of the client build at `clientDirectory`, a file path or a `file:` URL. */
|
|
188
|
+
files: (clientDirectory: string) => StaticFiles;
|
|
189
|
+
/**
|
|
190
|
+
* The listeners when the app sets none. A serverless host has none: it
|
|
191
|
+
* calls the entry's `fetch` for each request.
|
|
192
|
+
*/
|
|
193
|
+
listeners?: () => readonly Listener[];
|
|
194
|
+
/** The storage for {@link requestContext}. Without it, `requestContext()` gives `undefined`. */
|
|
195
|
+
storage?: RequestStore;
|
|
196
|
+
/**
|
|
197
|
+
* Gzips a byte stream and flushes after each chunk. Without it,
|
|
198
|
+
* `streamingCompress` sends each response as it is.
|
|
199
|
+
*/
|
|
200
|
+
gzip?: (source: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array>;
|
|
201
|
+
lifecycle?: Lifecycle;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* What a listener passes to the app with each request. A host can add its own
|
|
205
|
+
* values, such as Node's request and response.
|
|
206
|
+
*/
|
|
207
|
+
type ListenerBindings = {
|
|
208
|
+
/** The client's IP address, when the runtime knows it. */
|
|
209
|
+
remoteAddress?: string | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Given by a listener that writes each response itself, such as the node
|
|
212
|
+
* listener. See {@link ResponseEdge}.
|
|
213
|
+
*/
|
|
214
|
+
edge?: ResponseEdge | undefined;
|
|
215
|
+
[binding: string]: unknown;
|
|
216
|
+
};
|
|
217
|
+
/** The Hono bindings of an app server: the listener's values and the framework. */
|
|
218
|
+
type ServerBindings = ListenerBindings & {
|
|
219
|
+
framework: FrameworkRuntime;
|
|
220
|
+
};
|
|
221
|
+
/** The Hono environment of an app server. */
|
|
222
|
+
type AppServerEnv = {
|
|
223
|
+
Bindings: ServerBindings;
|
|
224
|
+
Variables: {
|
|
225
|
+
/** The request ID, set by the `requestId` plugin. */
|
|
226
|
+
requestId?: string;
|
|
227
|
+
logger: RequestLogger;
|
|
228
|
+
/** The nonce for the request's inline scripts, set by the `contentSecurityPolicy` plugin. */
|
|
229
|
+
cspNonce?: string;
|
|
230
|
+
/**
|
|
231
|
+
* The URL path of the client build's HTML file that the response sends,
|
|
232
|
+
* such as `/about/index.html`. The static stages set it, for a 304 too.
|
|
233
|
+
*/
|
|
234
|
+
staticDocument?: string;
|
|
235
|
+
/**
|
|
236
|
+
* The hashes of the inline scripts of an HTML file that the dev server
|
|
237
|
+
* sends as it is on disk, such as a file of Vite's public directory. The
|
|
238
|
+
* dev server stage sets it, for a 304 too.
|
|
239
|
+
*/
|
|
240
|
+
documentScriptHashes?: readonly string[];
|
|
241
|
+
/** The client's IP address. See `trustedProxyHops` on `createServer`. */
|
|
242
|
+
clientAddress?: string | undefined;
|
|
243
|
+
/** Attributes that each log line of the request carries, such as the trace IDs from the `requestId` plugin. */
|
|
244
|
+
logAttributes?: Readonly<Record<string, unknown>>;
|
|
245
|
+
/**
|
|
246
|
+
* The `etagPart` of each plugin that the request passed, in order. The
|
|
247
|
+
* static stages add them to each file's ETag. The server sets this list.
|
|
248
|
+
*/
|
|
249
|
+
etagParts?: readonly string[];
|
|
250
|
+
/**
|
|
251
|
+
* Whether a stage that the request passed changes the bytes of an HTML
|
|
252
|
+
* body, as `runtimeEnv` does. The stage sets it before its `next()`.
|
|
253
|
+
* The static stages then send an HTML file as it is on disk, not its
|
|
254
|
+
* compressed copy, so the stage can change it.
|
|
255
|
+
*/
|
|
256
|
+
rewritesHtml?: boolean;
|
|
257
|
+
/** The header hook of each stage that the request passed, in order. See {@link HeaderHook}. */
|
|
258
|
+
headerHooks?: HeaderHook[];
|
|
259
|
+
/** The reports of `onResponseSent` for the request. The server sets this list. */
|
|
260
|
+
sentReports?: ((sent: SentResponse) => void)[];
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
/** The headers of a response, for a {@link HeaderHook}. */
|
|
264
|
+
type ResponseHeaders = {
|
|
265
|
+
get: (name: string) => string | null;
|
|
266
|
+
has: (name: string) => boolean;
|
|
267
|
+
set: (name: string, value: string) => undefined;
|
|
268
|
+
append: (name: string, value: string) => undefined;
|
|
269
|
+
delete: (name: string) => undefined;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* A change to the headers of a response, from a stage that runs before the
|
|
273
|
+
* response. In an app server, it changes the head once, where the response
|
|
274
|
+
* leaves, after the code that each stage runs after its `next()`: the hook of
|
|
275
|
+
* an inner stage runs first, so an outer stage has the last word. A hook that
|
|
276
|
+
* throws gives a 500, as a stage that throws does. A dev server middleware
|
|
277
|
+
* that sends its own response runs the hooks before it sends the head.
|
|
278
|
+
*
|
|
279
|
+
* The static stages and `streamingCompress` also run the hooks on a view of
|
|
280
|
+
* the headers, to read the `Cache-Control` that leaves. So a hook can run two
|
|
281
|
+
* or three times for one request: each run must give the same headers and do
|
|
282
|
+
* nothing else, such as log, count, or store a value. A view run can come
|
|
283
|
+
* before the code that a stage runs after its `next()`, and a throw in it
|
|
284
|
+
* changes nothing.
|
|
285
|
+
*/
|
|
286
|
+
type HeaderHook = (headers: ResponseHeaders) => undefined;
|
|
287
|
+
/** The request handler that a listener calls. */
|
|
288
|
+
type FetchHandler = (request: Request, bindings: ListenerBindings) => Response | Promise<Response>;
|
|
289
|
+
/** What a plugin learns at startup, before the first request. */
|
|
290
|
+
type SetupInfo = {
|
|
291
|
+
/** The files of the client build. */
|
|
292
|
+
files: StaticFiles;
|
|
293
|
+
/** The headers of each prerendered file, by URL path, that the Vite plugin captured. */
|
|
294
|
+
capturedHeaders: ReadonlyMap<string, Readonly<Record<string, string>>>;
|
|
295
|
+
/**
|
|
296
|
+
* The base64 `SHA-256` of each inline script of each HTML file in the client
|
|
297
|
+
* build, by the file's URL path, that the Vite plugin recorded.
|
|
298
|
+
*/
|
|
299
|
+
scriptHashes: ReadonlyMap<string, readonly string[]>;
|
|
300
|
+
/**
|
|
301
|
+
* The ID of the client build that the Vite plugin derived. It is
|
|
302
|
+
* `undefined` in development and for a build with no build manifest.
|
|
303
|
+
*/
|
|
304
|
+
buildId: string | undefined;
|
|
305
|
+
/** Whether a URL path is a data request of the framework. */
|
|
306
|
+
isDataRequest: (path: string) => boolean;
|
|
307
|
+
/** Content types of the framework's files that `mime` does not know, by file extension. */
|
|
308
|
+
contentTypes: Readonly<Record<string, string>>;
|
|
309
|
+
/** The host's gzip stream, when it has one. */
|
|
310
|
+
gzip: ((source: ReadableStream<Uint8Array>) => ReadableStream<Uint8Array>) | undefined;
|
|
311
|
+
logger: LogSink;
|
|
312
|
+
} & ({
|
|
313
|
+
mode: "production";
|
|
314
|
+
/** The URL paths that the build prerendered. */
|
|
315
|
+
prerenderedPaths: readonly string[];
|
|
316
|
+
} | {
|
|
317
|
+
mode: "development";
|
|
318
|
+
/** The dev server as a pipeline stage. It serves source modules, HMR, and CSS. */
|
|
319
|
+
devServer: MiddlewareHandler<AppServerEnv>;
|
|
320
|
+
/**
|
|
321
|
+
* The URL paths that the build will prerender, or `undefined` when the
|
|
322
|
+
* framework finds them only during the build, as TanStack Start does.
|
|
323
|
+
*/
|
|
324
|
+
prerenderedPaths: readonly string[] | undefined;
|
|
325
|
+
});
|
|
326
|
+
/**
|
|
327
|
+
* One step of the request pipeline. Plugins run in list order, so the order is
|
|
328
|
+
* the contract.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* const livez: Plugin = {
|
|
332
|
+
* name: "livez",
|
|
333
|
+
* middleware: async (c, next) => (c.req.path === "/livez" ? c.text("ok") : next()),
|
|
334
|
+
* };
|
|
335
|
+
*/
|
|
336
|
+
type Plugin = {
|
|
337
|
+
/** A name for logs and errors. */
|
|
338
|
+
name: string;
|
|
339
|
+
/** The Hono middleware for this step. */
|
|
340
|
+
middleware?: MiddlewareHandler<AppServerEnv>;
|
|
341
|
+
/**
|
|
342
|
+
* Runs once before the server takes requests. A thrown error stops startup.
|
|
343
|
+
* On a serverless host, a thrown error fails the request, and the next
|
|
344
|
+
* request runs each `setup` again.
|
|
345
|
+
*/
|
|
346
|
+
setup?: (info: SetupInfo) => void | Promise<void>;
|
|
347
|
+
/** Runs at shutdown while the listeners drain. The server stops waiting for it at the drain deadline. */
|
|
348
|
+
onShutdown?: () => Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* A value that this plugin's changes to a response depend on, such as the
|
|
351
|
+
* env values it writes into each document. The server adds it to the ETag
|
|
352
|
+
* of each static file that the request reaches after this plugin, so a 304
|
|
353
|
+
* never keeps a response made with an old value. Return `undefined` when
|
|
354
|
+
* the plugin changes nothing.
|
|
355
|
+
*/
|
|
356
|
+
etagPart?: () => string | undefined;
|
|
357
|
+
};
|
|
358
|
+
/** A running listener. */
|
|
359
|
+
type StartedListener = {
|
|
360
|
+
/** The URL the listener answers on. */
|
|
361
|
+
url: string;
|
|
362
|
+
/**
|
|
363
|
+
* Stops new connections and waits for open requests. At the deadline, it
|
|
364
|
+
* closes the connections that are still open.
|
|
365
|
+
*/
|
|
366
|
+
stop: (options: {
|
|
367
|
+
deadlineMs: number;
|
|
368
|
+
}) => Promise<void>;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* How the server receives connections, separate from the request pipeline.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* createServer({ listeners: [tcp({ port: 8080 })] });
|
|
375
|
+
*/
|
|
376
|
+
type Listener = {
|
|
377
|
+
/** A name for logs. */
|
|
378
|
+
name: string;
|
|
379
|
+
start: (fetch: FetchHandler, options?: ListenerStartOptions) => Promise<StartedListener>;
|
|
380
|
+
};
|
|
381
|
+
/** What the server tells a listener when it starts it. */
|
|
382
|
+
type ListenerStartOptions = {
|
|
383
|
+
/**
|
|
384
|
+
* The `trustForwardedProto` of the server. A listener that builds each
|
|
385
|
+
* request itself can then take the scheme from `X-Forwarded-Proto` at once,
|
|
386
|
+
* so the server copies no request to change it.
|
|
387
|
+
* @default false
|
|
388
|
+
*/
|
|
389
|
+
trustForwardedProto?: boolean;
|
|
390
|
+
};
|
|
391
|
+
export { SetupInfo as C, ResponseEdge as E, ServerBindings as S, StaticFiles as T, RequestContext as _, FrameworkRuntime as a, ResponseHeaders as b, HostRuntime as c, ListenerBindings as d, ListenerStartOptions as f, Plugin as g, Mode as h, FileInfo as i, Lifecycle as l, LogSink as m, ByteRange as n, FrameworkRuntimeFactory as o, LogLevel as p, FetchHandler as r, HeaderHook as s, AppServerEnv as t, Listener as u, RequestLogger as v, StartedListener as w, SentResponse as x, RequestStore as y };
|
|
392
|
+
//# sourceMappingURL=types-DLYxYS6M.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { r as HostBuild } from "./index-Bo5G9LuQ.js";
|
|
2
|
+
/** Options for {@link vercel}. */
|
|
3
|
+
export type VercelOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* More URL path prefixes of the client build that Vercel's CDN serves,
|
|
6
|
+
* such as `["/blog-assets/"]`. Each starts and ends with `/`. `/assets/`
|
|
7
|
+
* is always one. Their files skip the pipeline, and the function does not
|
|
8
|
+
* carry them.
|
|
9
|
+
*/
|
|
10
|
+
cdnPaths?: readonly string[];
|
|
11
|
+
/** Headers for each file that the CDN serves, such as CORS headers. */
|
|
12
|
+
cdnHeaders?: Readonly<Record<string, string>>;
|
|
13
|
+
/** The Vercel regions of the function, such as `["iad1"]`. @default the project's */
|
|
14
|
+
regions?: readonly string[];
|
|
15
|
+
/** The memory of the function, in MB. @default the project's */
|
|
16
|
+
memory?: number;
|
|
17
|
+
/** The longest time that a request runs, in seconds. @default the project's */
|
|
18
|
+
maxDuration?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The build side of the vercel host. After the build, it writes
|
|
22
|
+
* `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:
|
|
23
|
+
*
|
|
24
|
+
* - `static/`: the files under `/assets/` and the other `cdnPaths`. The CDN
|
|
25
|
+
* serves them, and each file under `/assets/` gets a one-year immutable
|
|
26
|
+
* cache.
|
|
27
|
+
* - `functions/index.func/`: one Node.js function that runs the pipeline for
|
|
28
|
+
* each other request, with the whole server build and the rest of the
|
|
29
|
+
* client build.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* appServer({ host: vercel() });
|
|
33
|
+
*/
|
|
34
|
+
export declare function vercel(options?: VercelOptions): HostBuild;
|
|
35
|
+
//# sourceMappingURL=vercel-vite.d.ts.map
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { r as hasDotSegment } from "./static-files-Beju9riB.js";
|
|
2
|
+
import { copyFileSync, cpSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/vercel/vite.ts
|
|
6
|
+
/** The hashed files of the client build. Their names change with their content. */
|
|
7
|
+
const ASSETS = "/assets/";
|
|
8
|
+
const IMMUTABLE = "public, max-age=31536000, immutable";
|
|
9
|
+
/** The variable that gives the function the time of the build, in milliseconds. */
|
|
10
|
+
const BUILT_AT = "APP_SERVER_BUILT_AT";
|
|
11
|
+
/** The function's file, next to the server entry. */
|
|
12
|
+
const FUNCTION_FILE = "vercel-function.js";
|
|
13
|
+
/** A path with `/` separators, as Vercel's config reads it. */
|
|
14
|
+
function posix(path) {
|
|
15
|
+
return path.split(sep).join("/");
|
|
16
|
+
}
|
|
17
|
+
/** A regular expression source that matches `text` as it is. */
|
|
18
|
+
function escaped(text) {
|
|
19
|
+
return text.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`);
|
|
20
|
+
}
|
|
21
|
+
/** Copies the file at `from` to `to`, and makes the directories of `to`. */
|
|
22
|
+
function copyFile(from, to) {
|
|
23
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
24
|
+
copyFileSync(from, to);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The path of each file under `directory`, relative to it. Why follow links:
|
|
28
|
+
* the CDN and the function each get a copy of the linked file, not a link
|
|
29
|
+
* whose target can be in the other part. Why the inodes of the parents: a
|
|
30
|
+
* link to a parent directory must not make the walk endless.
|
|
31
|
+
*/
|
|
32
|
+
function filesUnder(directory, under = "", parents = /* @__PURE__ */ new Set()) {
|
|
33
|
+
const stats = statSync(join(directory, under), { throwIfNoEntry: false });
|
|
34
|
+
if (stats == null) return [];
|
|
35
|
+
if (!stats.isDirectory()) return [under];
|
|
36
|
+
const inode = `${stats.dev}:${stats.ino}`;
|
|
37
|
+
if (parents.has(inode)) return [];
|
|
38
|
+
const inside = new Set(parents).add(inode);
|
|
39
|
+
return readdirSync(join(directory, under)).flatMap((name) => filesUnder(directory, join(under, name), inside));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The `.vercel/output` routes: a CDN file gets its headers, and each other
|
|
43
|
+
* request goes to the function. Why the `hit` phase: a CDN path with no file
|
|
44
|
+
* goes to the function, whose `no-store` 404 must not get the immutable cache.
|
|
45
|
+
*/
|
|
46
|
+
function routes(prefixes, cdnHeaders) {
|
|
47
|
+
return [
|
|
48
|
+
{ handle: "filesystem" },
|
|
49
|
+
{
|
|
50
|
+
src: "^/(.*)$",
|
|
51
|
+
dest: "/index"
|
|
52
|
+
},
|
|
53
|
+
{ handle: "hit" },
|
|
54
|
+
...prefixes.map((prefix) => ({
|
|
55
|
+
src: `^${escaped(prefix)}.*$`,
|
|
56
|
+
headers: prefix === ASSETS ? {
|
|
57
|
+
...cdnHeaders,
|
|
58
|
+
"Cache-Control": IMMUTABLE
|
|
59
|
+
} : cdnHeaders,
|
|
60
|
+
continue: true
|
|
61
|
+
}))
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
/** Writes `.vercel/output` (the Build Output API, version 3) for one build. */
|
|
65
|
+
function writeOutput({ root, clientDirectory, entryFile }, { cdnPaths = [], cdnHeaders = {}, regions, memory, maxDuration }) {
|
|
66
|
+
const prefixes = [ASSETS, ...cdnPaths.filter((path) => path !== ASSETS)];
|
|
67
|
+
const output = join(root, ".vercel/output");
|
|
68
|
+
rmSync(output, {
|
|
69
|
+
recursive: true,
|
|
70
|
+
force: true
|
|
71
|
+
});
|
|
72
|
+
const fromRoot = (path) => {
|
|
73
|
+
const inside = relative(root, path);
|
|
74
|
+
if (inside.startsWith("..") || isAbsolute(inside)) throw new Error(`@ngrok/app-server/vercel needs ${path} inside the Vite root ${root}.`);
|
|
75
|
+
return inside;
|
|
76
|
+
};
|
|
77
|
+
const functionDirectory = join(output, "functions/index.func");
|
|
78
|
+
const isCdnFile = (file) => prefixes.some((prefix) => `/${posix(file)}`.startsWith(prefix));
|
|
79
|
+
for (const file of filesUnder(clientDirectory)) {
|
|
80
|
+
const from = join(clientDirectory, file);
|
|
81
|
+
if (!isCdnFile(file)) copyFile(from, join(functionDirectory, fromRoot(from)));
|
|
82
|
+
else if (!hasDotSegment(`/${posix(file)}`)) copyFile(from, join(output, "static", file));
|
|
83
|
+
}
|
|
84
|
+
const serverDirectory = dirname(entryFile);
|
|
85
|
+
const functionFile = join(serverDirectory, FUNCTION_FILE);
|
|
86
|
+
cpSync(serverDirectory, join(functionDirectory, fromRoot(serverDirectory)), {
|
|
87
|
+
recursive: true,
|
|
88
|
+
dereference: true,
|
|
89
|
+
filter: (path) => path !== clientDirectory
|
|
90
|
+
});
|
|
91
|
+
writeFileSync(join(functionDirectory, fromRoot(functionFile)), [
|
|
92
|
+
`import { appServer, hostModule } from ${JSON.stringify(`./${basename(entryFile)}`)};`,
|
|
93
|
+
`export default hostModule.handler(appServer);`,
|
|
94
|
+
""
|
|
95
|
+
].join("\n"));
|
|
96
|
+
writeFileSync(join(functionDirectory, ".vc-config.json"), `${JSON.stringify({
|
|
97
|
+
runtime: `nodejs${process.versions.node.split(".")[0]}.x`,
|
|
98
|
+
handler: posix(fromRoot(functionFile)),
|
|
99
|
+
launcherType: "Nodejs",
|
|
100
|
+
supportsResponseStreaming: true,
|
|
101
|
+
environment: { [BUILT_AT]: String(Date.now()) },
|
|
102
|
+
...regions == null ? {} : { regions },
|
|
103
|
+
...memory == null ? {} : { memory },
|
|
104
|
+
...maxDuration == null ? {} : { maxDuration }
|
|
105
|
+
}, null, " ")}\n`);
|
|
106
|
+
writeFileSync(join(output, "config.json"), `${JSON.stringify({
|
|
107
|
+
version: 3,
|
|
108
|
+
routes: routes(prefixes, cdnHeaders)
|
|
109
|
+
}, null, " ")}\n`);
|
|
110
|
+
}
|
|
111
|
+
/** Throws for a CDN path that is not a URL path prefix, so the config fails, not the deploy. */
|
|
112
|
+
function checkCdnPaths(paths) {
|
|
113
|
+
for (const path of paths) if (!path.startsWith("/") || !path.endsWith("/") || path === "/" || path.includes("..")) throw new Error(`Each cdnPaths entry is a URL path prefix that starts and ends with "/", such as "/blog-assets/", not ${JSON.stringify(path)}.`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The build side of the vercel host. After the build, it writes
|
|
117
|
+
* `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:
|
|
118
|
+
*
|
|
119
|
+
* - `static/`: the files under `/assets/` and the other `cdnPaths`. The CDN
|
|
120
|
+
* serves them, and each file under `/assets/` gets a one-year immutable
|
|
121
|
+
* cache.
|
|
122
|
+
* - `functions/index.func/`: one Node.js function that runs the pipeline for
|
|
123
|
+
* each other request, with the whole server build and the rest of the
|
|
124
|
+
* client build.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* appServer({ host: vercel() });
|
|
128
|
+
*/
|
|
129
|
+
function vercel(options = {}) {
|
|
130
|
+
checkCdnPaths(options.cdnPaths ?? []);
|
|
131
|
+
return {
|
|
132
|
+
name: "vercel",
|
|
133
|
+
runtimeModule: "@ngrok/app-server/vercel",
|
|
134
|
+
entryFileName: "app-server.js",
|
|
135
|
+
output: (build) => {
|
|
136
|
+
writeOutput(build, options);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { vercel };
|
|
142
|
+
//# sourceMappingURL=vercel-vite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercel-vite.js","names":[],"sources":["../src/vercel/vite.ts"],"sourcesContent":["import {\n\tcopyFileSync,\n\tcpSync,\n\tmkdirSync,\n\treaddirSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { basename, dirname, isAbsolute, join, relative, sep } from \"node:path\";\nimport { hasDotSegment } from \"../core/static-files.js\";\nimport type { HostBuild, HostOutput } from \"../vite/index.js\";\n\n/** Options for {@link vercel}. */\nexport type VercelOptions = {\n\t/**\n\t * More URL path prefixes of the client build that Vercel's CDN serves,\n\t * such as `[\"/blog-assets/\"]`. Each starts and ends with `/`. `/assets/`\n\t * is always one. Their files skip the pipeline, and the function does not\n\t * carry them.\n\t */\n\tcdnPaths?: readonly string[];\n\t/** Headers for each file that the CDN serves, such as CORS headers. */\n\tcdnHeaders?: Readonly<Record<string, string>>;\n\t/** The Vercel regions of the function, such as `[\"iad1\"]`. @default the project's */\n\tregions?: readonly string[];\n\t/** The memory of the function, in MB. @default the project's */\n\tmemory?: number;\n\t/** The longest time that a request runs, in seconds. @default the project's */\n\tmaxDuration?: number;\n};\n\n/** The hashed files of the client build. Their names change with their content. */\nconst ASSETS = \"/assets/\";\n\nconst IMMUTABLE = \"public, max-age=31536000, immutable\";\n\n/** The variable that gives the function the time of the build, in milliseconds. */\nconst BUILT_AT = \"APP_SERVER_BUILT_AT\";\n\n/** The function's file, next to the server entry. */\nconst FUNCTION_FILE = \"vercel-function.js\";\n\n/** A path with `/` separators, as Vercel's config reads it. */\nfunction posix(path: string): string {\n\treturn path.split(sep).join(\"/\");\n}\n\n/** A regular expression source that matches `text` as it is. */\nfunction escaped(text: string): string {\n\treturn text.replaceAll(/[$()*+.?[\\\\\\]^{|}]/gu, String.raw`\\$&`);\n}\n\n/** Copies the file at `from` to `to`, and makes the directories of `to`. */\nfunction copyFile(from: string, to: string): void {\n\tmkdirSync(dirname(to), { recursive: true });\n\tcopyFileSync(from, to);\n}\n\n/**\n * The path of each file under `directory`, relative to it. Why follow links:\n * the CDN and the function each get a copy of the linked file, not a link\n * whose target can be in the other part. Why the inodes of the parents: a\n * link to a parent directory must not make the walk endless.\n */\nfunction filesUnder(\n\tdirectory: string,\n\tunder = \"\",\n\tparents: ReadonlySet<string> = new Set(),\n): string[] {\n\tconst stats = statSync(join(directory, under), { throwIfNoEntry: false });\n\tif (stats == null) {\n\t\treturn [];\n\t}\n\tif (!stats.isDirectory()) {\n\t\treturn [under];\n\t}\n\tconst inode = `${stats.dev}:${stats.ino}`;\n\tif (parents.has(inode)) {\n\t\treturn [];\n\t}\n\tconst inside = new Set(parents).add(inode);\n\treturn readdirSync(join(directory, under)).flatMap((name) =>\n\t\tfilesUnder(directory, join(under, name), inside),\n\t);\n}\n\n/**\n * The `.vercel/output` routes: a CDN file gets its headers, and each other\n * request goes to the function. Why the `hit` phase: a CDN path with no file\n * goes to the function, whose `no-store` 404 must not get the immutable cache.\n */\nfunction routes(prefixes: readonly string[], cdnHeaders: Readonly<Record<string, string>>) {\n\treturn [\n\t\t{ handle: \"filesystem\" },\n\t\t{ src: \"^/(.*)$\", dest: \"/index\" },\n\t\t{ handle: \"hit\" },\n\t\t...prefixes.map((prefix) => ({\n\t\t\t// Why `.*$`: Vercel adds `$` to a pattern that has none.\n\t\t\tsrc: `^${escaped(prefix)}.*$`,\n\t\t\theaders: prefix === ASSETS ? { ...cdnHeaders, \"Cache-Control\": IMMUTABLE } : cdnHeaders,\n\t\t\tcontinue: true,\n\t\t})),\n\t];\n}\n\n/** Writes `.vercel/output` (the Build Output API, version 3) for one build. */\nfunction writeOutput(\n\t{ root, clientDirectory, entryFile }: HostOutput,\n\t{ cdnPaths = [], cdnHeaders = {}, regions, memory, maxDuration }: VercelOptions,\n): void {\n\tconst prefixes = [ASSETS, ...cdnPaths.filter((path) => path !== ASSETS)];\n\tconst output = join(root, \".vercel/output\");\n\trmSync(output, { recursive: true, force: true });\n\tconst fromRoot = (path: string): string => {\n\t\tconst inside = relative(root, path);\n\t\tif (inside.startsWith(\"..\") || isAbsolute(inside)) {\n\t\t\tthrow new Error(`@ngrok/app-server/vercel needs ${path} inside the Vite root ${root}.`);\n\t\t}\n\t\treturn inside;\n\t};\n\tconst functionDirectory = join(output, \"functions/index.func\");\n\tconst isCdnFile = (file: string): boolean =>\n\t\tprefixes.some((prefix) => `/${posix(file)}`.startsWith(prefix));\n\n\tfor (const file of filesUnder(clientDirectory)) {\n\t\tconst from = join(clientDirectory, file);\n\t\tif (!isCdnFile(file)) {\n\t\t\tcopyFile(from, join(functionDirectory, fromRoot(from)));\n\t\t} else if (!hasDotSegment(`/${posix(file)}`)) {\n\t\t\t// Why the static stages' check: the CDN sends each file that it has, and the static stages\n\t\t\t// send no dotfile, such as a compressed copy, and no file in a dot directory.\n\t\t\tcopyFile(from, join(output, \"static\", file));\n\t\t}\n\t}\n\n\t// Why the whole server build: it runs with no install, and it keeps the client build's path.\n\tconst serverDirectory = dirname(entryFile);\n\tconst functionFile = join(serverDirectory, FUNCTION_FILE);\n\tcpSync(serverDirectory, join(functionDirectory, fromRoot(serverDirectory)), {\n\t\trecursive: true,\n\t\t// Why: a link that keeps its target can point at the build machine.\n\t\tdereference: true,\n\t\t// Why: the client build can be inside the server build, and the loop above copied its part.\n\t\tfilter: (path) => path !== clientDirectory,\n\t});\n\twriteFileSync(\n\t\tjoin(functionDirectory, fromRoot(functionFile)),\n\t\t[\n\t\t\t`import { appServer, hostModule } from ${JSON.stringify(`./${basename(entryFile)}`)};`,\n\t\t\t`export default hostModule.handler(appServer);`,\n\t\t\t\"\",\n\t\t].join(\"\\n\"),\n\t);\n\twriteFileSync(\n\t\tjoin(functionDirectory, \".vc-config.json\"),\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\t// Why the build's Node.js: the server build targets the Node.js that built it.\n\t\t\t\truntime: `nodejs${process.versions.node.split(\".\")[0]}.x`,\n\t\t\t\thandler: posix(fromRoot(functionFile)),\n\t\t\t\tlauncherType: \"Nodejs\",\n\t\t\t\tsupportsResponseStreaming: true,\n\t\t\t\t// Why: the deploy gives each file of the function one fixed time, and the ETag of a file\n\t\t\t\t// reads its time. See `host` in `@ngrok/app-server/vercel`.\n\t\t\t\tenvironment: { [BUILT_AT]: String(Date.now()) },\n\t\t\t\t...(regions == null ? {} : { regions }),\n\t\t\t\t...(memory == null ? {} : { memory }),\n\t\t\t\t...(maxDuration == null ? {} : { maxDuration }),\n\t\t\t},\n\t\t\tnull,\n\t\t\t\"\\t\",\n\t\t)}\\n`,\n\t);\n\twriteFileSync(\n\t\tjoin(output, \"config.json\"),\n\t\t`${JSON.stringify({ version: 3, routes: routes(prefixes, cdnHeaders) }, null, \"\\t\")}\\n`,\n\t);\n}\n\n/** Throws for a CDN path that is not a URL path prefix, so the config fails, not the deploy. */\nfunction checkCdnPaths(paths: readonly string[]): void {\n\tfor (const path of paths) {\n\t\tif (!path.startsWith(\"/\") || !path.endsWith(\"/\") || path === \"/\" || path.includes(\"..\")) {\n\t\t\tthrow new Error(\n\t\t\t\t`Each cdnPaths entry is a URL path prefix that starts and ends with \"/\", such as \"/blog-assets/\", not ${JSON.stringify(path)}.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The build side of the vercel host. After the build, it writes\n * `.vercel/output` in the Vite root, for `vercel deploy --prebuilt`:\n *\n * - `static/`: the files under `/assets/` and the other `cdnPaths`. The CDN\n * serves them, and each file under `/assets/` gets a one-year immutable\n * cache.\n * - `functions/index.func/`: one Node.js function that runs the pipeline for\n * each other request, with the whole server build and the rest of the\n * client build.\n *\n * @example\n * appServer({ host: vercel() });\n */\nexport function vercel(options: VercelOptions = {}): HostBuild {\n\tcheckCdnPaths(options.cdnPaths ?? []);\n\treturn {\n\t\tname: \"vercel\",\n\t\truntimeModule: \"@ngrok/app-server/vercel\",\n\t\tentryFileName: \"app-server.js\",\n\t\toutput: (build) => {\n\t\t\twriteOutput(build, options);\n\t\t},\n\t};\n}\n"],"mappings":"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"}
|
package/dist/vercel.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { c as HostRuntime } from "./types-DLYxYS6M.js";
|
|
2
|
+
import { t as AppServerEntry } from "./entry-CM6Ma-Tv.js";
|
|
3
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
/**
|
|
5
|
+
* The vercel host: one Vercel Function on Node.js. It reads the client build
|
|
6
|
+
* from the function's files and keeps `requestContext()` in
|
|
7
|
+
* `AsyncLocalStorage`, as the node host does. It has no listeners and no
|
|
8
|
+
* lifecycle: Vercel starts and stops the function, and {@link handler} calls
|
|
9
|
+
* the entry's `fetch`.
|
|
10
|
+
*
|
|
11
|
+
* Why no gzip: Vercel's CDN compresses each response, with Brotli when the
|
|
12
|
+
* client accepts it.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* export const appServer = createEntry({ app, host, framework: (mode) => runtime(build, { mode }) });
|
|
16
|
+
*/
|
|
17
|
+
export declare const host: HostRuntime;
|
|
18
|
+
/**
|
|
19
|
+
* The function handler for the entry of a server build. The function file
|
|
20
|
+
* that `vercel()` writes exports it.
|
|
21
|
+
*
|
|
22
|
+
* - The scheme comes from `X-Forwarded-Proto`, and the client address from
|
|
23
|
+
* `X-Real-IP`. Why trust them: Vercel sets both headers on each request,
|
|
24
|
+
* and replaces a value that the client sends.
|
|
25
|
+
* - The node response writer sends each response, as the node host's
|
|
26
|
+
* listener does.
|
|
27
|
+
* - The log lines of the request reach stdout before the handler returns.
|
|
28
|
+
* Why: Vercel can freeze the function after the response, before the next
|
|
29
|
+
* turn of the event loop writes them.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* export default hostModule.handler(appServer);
|
|
33
|
+
*/
|
|
34
|
+
export declare function handler(entry: AppServerEntry): (incoming: IncomingMessage, outgoing: ServerResponse) => Promise<void>;
|
|
35
|
+
//# sourceMappingURL=vercel.d.ts.map
|