srvx 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_middleware.mjs +13 -0
- package/dist/_plugins.mjs +16 -0
- package/dist/_url.d.mts +13 -0
- package/dist/_url.mjs +151 -0
- package/dist/bun.d.mts +22 -0
- package/dist/bun.mjs +77 -0
- package/dist/cloudflare.d.mts +10 -0
- package/dist/cloudflare.mjs +53 -0
- package/dist/deno.d.mts +22 -0
- package/dist/deno.mjs +86 -0
- package/dist/generic.d.mts +9 -0
- package/dist/generic.mjs +36 -0
- package/dist/node.d.mts +55 -0
- package/dist/node.mjs +813 -0
- package/dist/{adapters/service-worker.d.mts → service-worker.d.mts} +4 -8
- package/dist/service-worker.mjs +80 -0
- package/dist/types.d.mts +210 -217
- package/package.json +29 -26
- package/dist/adapters/bun.d.mts +0 -24
- package/dist/adapters/bun.mjs +0 -80
- package/dist/adapters/cloudflare.d.mts +0 -12
- package/dist/adapters/cloudflare.mjs +0 -54
- package/dist/adapters/deno.d.mts +0 -25
- package/dist/adapters/deno.mjs +0 -83
- package/dist/adapters/generic.d.mts +0 -12
- package/dist/adapters/generic.mjs +0 -28
- package/dist/adapters/node.d.mts +0 -55
- package/dist/adapters/node.mjs +0 -1014
- package/dist/adapters/service-worker.mjs +0 -95
- package/dist/shared/srvx.BMykKwGg.mjs +0 -16
- package/dist/shared/srvx.CEIXM-sv.mjs +0 -18
- package/dist/shared/srvx.Ctaz0clH.mjs +0 -172
- package/dist/shared/srvx.DEE2RO4O.d.mts +0 -5
- package/dist/shared/srvx.zEohKxBQ.mjs +0 -20
package/dist/adapters/node.mjs
DELETED
|
@@ -1,1014 +0,0 @@
|
|
|
1
|
-
import NodeHttp from 'node:http';
|
|
2
|
-
import NodeHttps from 'node:https';
|
|
3
|
-
import { splitSetCookieString } from 'cookie-es';
|
|
4
|
-
import { r as resolveTLSOptions, a as resolvePortAndHost, p as printListening, f as fmtURL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
5
|
-
export { F as FastURL } from '../shared/srvx.Ctaz0clH.mjs';
|
|
6
|
-
import { w as wrapFetch } from '../shared/srvx.zEohKxBQ.mjs';
|
|
7
|
-
import { e as errorPlugin } from '../shared/srvx.CEIXM-sv.mjs';
|
|
8
|
-
import 'node:fs';
|
|
9
|
-
|
|
10
|
-
async function sendNodeResponse(nodeRes, webRes) {
|
|
11
|
-
if (!webRes) {
|
|
12
|
-
nodeRes.statusCode = 500;
|
|
13
|
-
return endNodeResponse(nodeRes);
|
|
14
|
-
}
|
|
15
|
-
if (webRes.nodeResponse) {
|
|
16
|
-
const res = webRes.nodeResponse();
|
|
17
|
-
if (!nodeRes.headersSent) {
|
|
18
|
-
nodeRes.writeHead(res.status, res.statusText, res.headers.flat());
|
|
19
|
-
}
|
|
20
|
-
if (res.body) {
|
|
21
|
-
if (res.body instanceof ReadableStream) {
|
|
22
|
-
return streamBody(res.body, nodeRes);
|
|
23
|
-
} else if (typeof res.body?.pipe === "function") {
|
|
24
|
-
res.body.pipe(nodeRes);
|
|
25
|
-
return new Promise((resolve) => nodeRes.on("close", resolve));
|
|
26
|
-
}
|
|
27
|
-
nodeRes.write(res.body);
|
|
28
|
-
}
|
|
29
|
-
return endNodeResponse(nodeRes);
|
|
30
|
-
}
|
|
31
|
-
const headerEntries = [];
|
|
32
|
-
for (const [key, value] of webRes.headers) {
|
|
33
|
-
if (key === "set-cookie") {
|
|
34
|
-
for (const setCookie of splitSetCookieString(value)) {
|
|
35
|
-
headerEntries.push(["set-cookie", setCookie]);
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
headerEntries.push([key, value]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (!nodeRes.headersSent) {
|
|
42
|
-
nodeRes.writeHead(
|
|
43
|
-
webRes.status || 200,
|
|
44
|
-
webRes.statusText,
|
|
45
|
-
headerEntries.flat()
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes);
|
|
49
|
-
}
|
|
50
|
-
async function sendNodeUpgradeResponse(socket, res) {
|
|
51
|
-
const head = [
|
|
52
|
-
`HTTP/1.1 ${res.status || 200} ${res.statusText || ""}`,
|
|
53
|
-
...[...res.headers.entries()].map(
|
|
54
|
-
([key, value]) => `${encodeURIComponent(key)}: ${encodeURIComponent(value)}`
|
|
55
|
-
)
|
|
56
|
-
];
|
|
57
|
-
socket.write(head.join("\r\n") + "\r\n\r\n");
|
|
58
|
-
if (res.body) {
|
|
59
|
-
for await (const chunk of res.body) {
|
|
60
|
-
socket.write(chunk);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return new Promise((resolve) => {
|
|
64
|
-
socket.end(resolve);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function endNodeResponse(nodeRes) {
|
|
68
|
-
return new Promise((resolve) => nodeRes.end(resolve));
|
|
69
|
-
}
|
|
70
|
-
function streamBody(stream, nodeRes) {
|
|
71
|
-
if (nodeRes.destroyed) {
|
|
72
|
-
stream.cancel();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const reader = stream.getReader();
|
|
76
|
-
function streamCancel(error) {
|
|
77
|
-
reader.cancel(error).catch(() => {
|
|
78
|
-
});
|
|
79
|
-
if (error) {
|
|
80
|
-
nodeRes.destroy(error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function streamHandle({
|
|
84
|
-
done,
|
|
85
|
-
value
|
|
86
|
-
}) {
|
|
87
|
-
try {
|
|
88
|
-
if (done) {
|
|
89
|
-
nodeRes.end();
|
|
90
|
-
} else if (nodeRes.write(value)) {
|
|
91
|
-
reader.read().then(streamHandle, streamCancel);
|
|
92
|
-
} else {
|
|
93
|
-
nodeRes.once(
|
|
94
|
-
"drain",
|
|
95
|
-
() => reader.read().then(streamHandle, streamCancel)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
} catch (error) {
|
|
99
|
-
streamCancel(error instanceof Error ? error : void 0);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
nodeRes.on("close", streamCancel);
|
|
103
|
-
nodeRes.on("error", streamCancel);
|
|
104
|
-
reader.read().then(streamHandle, streamCancel);
|
|
105
|
-
return reader.closed.finally(() => {
|
|
106
|
-
nodeRes.off("close", streamCancel);
|
|
107
|
-
nodeRes.off("error", streamCancel);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const kNodeInspect = /* @__PURE__ */ Symbol.for(
|
|
112
|
-
"nodejs.util.inspect.custom"
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const NodeRequestHeaders = /* @__PURE__ */ (() => {
|
|
116
|
-
const _Headers = class Headers {
|
|
117
|
-
constructor(nodeCtx) {
|
|
118
|
-
this._node = nodeCtx;
|
|
119
|
-
}
|
|
120
|
-
append(name, value) {
|
|
121
|
-
name = name.toLowerCase();
|
|
122
|
-
const _headers = this._node.req.headers;
|
|
123
|
-
const _current = _headers[name];
|
|
124
|
-
if (_current) {
|
|
125
|
-
if (Array.isArray(_current)) {
|
|
126
|
-
_current.push(value);
|
|
127
|
-
} else {
|
|
128
|
-
_headers[name] = [_current, value];
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
_headers[name] = value;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
delete(name) {
|
|
135
|
-
name = name.toLowerCase();
|
|
136
|
-
this._node.req.headers[name] = void 0;
|
|
137
|
-
}
|
|
138
|
-
get(name) {
|
|
139
|
-
name = name.toLowerCase();
|
|
140
|
-
const rawValue = this._node.req.headers[name];
|
|
141
|
-
if (rawValue === void 0) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
return _normalizeValue(this._node.req.headers[name]);
|
|
145
|
-
}
|
|
146
|
-
getSetCookie() {
|
|
147
|
-
const setCookie = this._node.req.headers["set-cookie"];
|
|
148
|
-
if (!setCookie || setCookie.length === 0) {
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
return splitSetCookieString(setCookie);
|
|
152
|
-
}
|
|
153
|
-
has(name) {
|
|
154
|
-
name = name.toLowerCase();
|
|
155
|
-
return !!this._node.req.headers[name];
|
|
156
|
-
}
|
|
157
|
-
set(name, value) {
|
|
158
|
-
name = name.toLowerCase();
|
|
159
|
-
this._node.req.headers[name] = value;
|
|
160
|
-
}
|
|
161
|
-
get count() {
|
|
162
|
-
throw new Error("Method not implemented.");
|
|
163
|
-
}
|
|
164
|
-
getAll(_name) {
|
|
165
|
-
throw new Error("Method not implemented.");
|
|
166
|
-
}
|
|
167
|
-
toJSON() {
|
|
168
|
-
const _headers = this._node.req.headers;
|
|
169
|
-
const result = {};
|
|
170
|
-
for (const key in _headers) {
|
|
171
|
-
if (_headers[key]) {
|
|
172
|
-
result[key] = _normalizeValue(_headers[key]);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
forEach(cb, thisArg) {
|
|
178
|
-
const _headers = this._node.req.headers;
|
|
179
|
-
for (const key in _headers) {
|
|
180
|
-
if (_headers[key]) {
|
|
181
|
-
cb.call(
|
|
182
|
-
thisArg,
|
|
183
|
-
_normalizeValue(_headers[key]),
|
|
184
|
-
key,
|
|
185
|
-
this
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
*entries() {
|
|
191
|
-
const _headers = this._node.req.headers;
|
|
192
|
-
for (const key in _headers) {
|
|
193
|
-
yield [key, _normalizeValue(_headers[key])];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
*keys() {
|
|
197
|
-
const keys = Object.keys(this._node.req.headers);
|
|
198
|
-
for (const key of keys) {
|
|
199
|
-
yield key;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
*values() {
|
|
203
|
-
const values = Object.values(this._node.req.headers);
|
|
204
|
-
for (const value of values) {
|
|
205
|
-
yield _normalizeValue(value);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
[Symbol.iterator]() {
|
|
209
|
-
return this.entries()[Symbol.iterator]();
|
|
210
|
-
}
|
|
211
|
-
get [Symbol.toStringTag]() {
|
|
212
|
-
return "Headers";
|
|
213
|
-
}
|
|
214
|
-
[kNodeInspect]() {
|
|
215
|
-
return Object.fromEntries(this.entries());
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
Object.setPrototypeOf(_Headers.prototype, globalThis.Headers.prototype);
|
|
219
|
-
return _Headers;
|
|
220
|
-
})();
|
|
221
|
-
const NodeResponseHeaders = /* @__PURE__ */ (() => {
|
|
222
|
-
const _Headers = class Headers {
|
|
223
|
-
constructor(nodeCtx) {
|
|
224
|
-
this._node = nodeCtx;
|
|
225
|
-
}
|
|
226
|
-
append(name, value) {
|
|
227
|
-
this._node.res.appendHeader(name, value);
|
|
228
|
-
}
|
|
229
|
-
delete(name) {
|
|
230
|
-
this._node.res.removeHeader(name);
|
|
231
|
-
}
|
|
232
|
-
get(name) {
|
|
233
|
-
const rawValue = this._node.res.getHeader(name);
|
|
234
|
-
if (rawValue === void 0) {
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
return _normalizeValue(rawValue);
|
|
238
|
-
}
|
|
239
|
-
getSetCookie() {
|
|
240
|
-
const setCookie = _normalizeValue(this._node.res.getHeader("set-cookie"));
|
|
241
|
-
if (!setCookie) {
|
|
242
|
-
return [];
|
|
243
|
-
}
|
|
244
|
-
return splitSetCookieString(setCookie);
|
|
245
|
-
}
|
|
246
|
-
has(name) {
|
|
247
|
-
return this._node.res.hasHeader(name);
|
|
248
|
-
}
|
|
249
|
-
set(name, value) {
|
|
250
|
-
this._node.res.setHeader(name, value);
|
|
251
|
-
}
|
|
252
|
-
get count() {
|
|
253
|
-
throw new Error("Method not implemented.");
|
|
254
|
-
}
|
|
255
|
-
getAll(_name) {
|
|
256
|
-
throw new Error("Method not implemented.");
|
|
257
|
-
}
|
|
258
|
-
toJSON() {
|
|
259
|
-
const _headers = this._node.res.getHeaders();
|
|
260
|
-
const result = {};
|
|
261
|
-
for (const key in _headers) {
|
|
262
|
-
if (_headers[key]) {
|
|
263
|
-
result[key] = _normalizeValue(_headers[key]);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return result;
|
|
267
|
-
}
|
|
268
|
-
forEach(cb, thisArg) {
|
|
269
|
-
const _headers = this._node.res.getHeaders();
|
|
270
|
-
for (const key in _headers) {
|
|
271
|
-
if (_headers[key]) {
|
|
272
|
-
cb.call(
|
|
273
|
-
thisArg,
|
|
274
|
-
_normalizeValue(_headers[key]),
|
|
275
|
-
key,
|
|
276
|
-
this
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
*entries() {
|
|
282
|
-
const _headers = this._node.res.getHeaders();
|
|
283
|
-
for (const key in _headers) {
|
|
284
|
-
yield [key, _normalizeValue(_headers[key])];
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
*keys() {
|
|
288
|
-
const keys = this._node.res.getHeaderNames();
|
|
289
|
-
for (const key of keys) {
|
|
290
|
-
yield key;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
*values() {
|
|
294
|
-
const values = Object.values(this._node.res.getHeaders());
|
|
295
|
-
for (const value of values) {
|
|
296
|
-
yield _normalizeValue(value);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
[Symbol.iterator]() {
|
|
300
|
-
return this.entries()[Symbol.iterator]();
|
|
301
|
-
}
|
|
302
|
-
get [Symbol.toStringTag]() {
|
|
303
|
-
return "Headers";
|
|
304
|
-
}
|
|
305
|
-
[kNodeInspect]() {
|
|
306
|
-
return Object.fromEntries(this.entries());
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
Object.setPrototypeOf(_Headers.prototype, globalThis.Headers.prototype);
|
|
310
|
-
return _Headers;
|
|
311
|
-
})();
|
|
312
|
-
function _normalizeValue(value) {
|
|
313
|
-
if (Array.isArray(value)) {
|
|
314
|
-
return value.join(", ");
|
|
315
|
-
}
|
|
316
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const NodeRequestURL = /* @__PURE__ */ (() => {
|
|
320
|
-
const _URL = class URL {
|
|
321
|
-
constructor(nodeCtx) {
|
|
322
|
-
this._hash = "";
|
|
323
|
-
this._username = "";
|
|
324
|
-
this._password = "";
|
|
325
|
-
this._node = nodeCtx;
|
|
326
|
-
}
|
|
327
|
-
get hash() {
|
|
328
|
-
return this._hash;
|
|
329
|
-
}
|
|
330
|
-
set hash(value) {
|
|
331
|
-
this._hash = value;
|
|
332
|
-
}
|
|
333
|
-
get username() {
|
|
334
|
-
return this._username;
|
|
335
|
-
}
|
|
336
|
-
set username(value) {
|
|
337
|
-
this._username = value;
|
|
338
|
-
}
|
|
339
|
-
get password() {
|
|
340
|
-
return this._password;
|
|
341
|
-
}
|
|
342
|
-
set password(value) {
|
|
343
|
-
this._password = value;
|
|
344
|
-
}
|
|
345
|
-
// host
|
|
346
|
-
get host() {
|
|
347
|
-
return this._node.req.headers.host || "";
|
|
348
|
-
}
|
|
349
|
-
set host(value) {
|
|
350
|
-
this._hostname = void 0;
|
|
351
|
-
this._port = void 0;
|
|
352
|
-
this._node.req.headers.host = value;
|
|
353
|
-
}
|
|
354
|
-
// hostname
|
|
355
|
-
get hostname() {
|
|
356
|
-
if (this._hostname === void 0) {
|
|
357
|
-
const [hostname, port] = parseHost(this._node.req.headers.host);
|
|
358
|
-
if (this._port === void 0 && port) {
|
|
359
|
-
this._port = String(Number.parseInt(port) || "");
|
|
360
|
-
}
|
|
361
|
-
this._hostname = hostname || "localhost";
|
|
362
|
-
}
|
|
363
|
-
return this._hostname;
|
|
364
|
-
}
|
|
365
|
-
set hostname(value) {
|
|
366
|
-
this._hostname = value;
|
|
367
|
-
}
|
|
368
|
-
// port
|
|
369
|
-
get port() {
|
|
370
|
-
if (this._port === void 0) {
|
|
371
|
-
const [hostname, port] = parseHost(this._node.req.headers.host);
|
|
372
|
-
if (this._hostname === void 0 && hostname) {
|
|
373
|
-
this._hostname = hostname;
|
|
374
|
-
}
|
|
375
|
-
this._port = port || String(this._node.req.socket?.localPort || "");
|
|
376
|
-
}
|
|
377
|
-
return this._port;
|
|
378
|
-
}
|
|
379
|
-
set port(value) {
|
|
380
|
-
this._port = String(Number.parseInt(value) || "");
|
|
381
|
-
}
|
|
382
|
-
// pathname
|
|
383
|
-
get pathname() {
|
|
384
|
-
if (this._pathname === void 0) {
|
|
385
|
-
const [pathname, search] = parsePath(this._node.req.url || "/");
|
|
386
|
-
this._pathname = pathname;
|
|
387
|
-
if (this._search === void 0) {
|
|
388
|
-
this._search = search;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return this._pathname;
|
|
392
|
-
}
|
|
393
|
-
set pathname(value) {
|
|
394
|
-
if (value[0] !== "/") {
|
|
395
|
-
value = "/" + value;
|
|
396
|
-
}
|
|
397
|
-
if (value === this._pathname) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
this._pathname = value;
|
|
401
|
-
this._node.req.url = value + this.search;
|
|
402
|
-
}
|
|
403
|
-
// search
|
|
404
|
-
get search() {
|
|
405
|
-
if (this._search === void 0) {
|
|
406
|
-
const [pathname, search] = parsePath(this._node.req.url || "/");
|
|
407
|
-
this._search = search;
|
|
408
|
-
if (this._pathname === void 0) {
|
|
409
|
-
this._pathname = pathname;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return this._search;
|
|
413
|
-
}
|
|
414
|
-
set search(value) {
|
|
415
|
-
if (value === "?") {
|
|
416
|
-
value = "";
|
|
417
|
-
} else if (value && value[0] !== "?") {
|
|
418
|
-
value = "?" + value;
|
|
419
|
-
}
|
|
420
|
-
if (value === this._search) {
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
this._search = value;
|
|
424
|
-
this._searchParams = void 0;
|
|
425
|
-
this._node.req.url = this.pathname + value;
|
|
426
|
-
}
|
|
427
|
-
// searchParams
|
|
428
|
-
get searchParams() {
|
|
429
|
-
if (!this._searchParams) {
|
|
430
|
-
this._searchParams = new URLSearchParams(this.search);
|
|
431
|
-
}
|
|
432
|
-
return this._searchParams;
|
|
433
|
-
}
|
|
434
|
-
set searchParams(value) {
|
|
435
|
-
this._searchParams = value;
|
|
436
|
-
this._search = value.toString();
|
|
437
|
-
}
|
|
438
|
-
// protocol
|
|
439
|
-
get protocol() {
|
|
440
|
-
if (!this._protocol) {
|
|
441
|
-
this._protocol = this._node.req.socket?.encrypted || this._node.req.headers["x-forwarded-proto"] === "https" ? "https:" : "http:";
|
|
442
|
-
}
|
|
443
|
-
return this._protocol;
|
|
444
|
-
}
|
|
445
|
-
set protocol(value) {
|
|
446
|
-
this._protocol = value;
|
|
447
|
-
}
|
|
448
|
-
// origin
|
|
449
|
-
get origin() {
|
|
450
|
-
return `${this.protocol}//${this.host}`;
|
|
451
|
-
}
|
|
452
|
-
set origin(_value) {
|
|
453
|
-
}
|
|
454
|
-
// href
|
|
455
|
-
get href() {
|
|
456
|
-
return `${this.protocol}//${this.host}${this.pathname}${this.search}`;
|
|
457
|
-
}
|
|
458
|
-
set href(value) {
|
|
459
|
-
const _url = new globalThis.URL(value);
|
|
460
|
-
this._protocol = _url.protocol;
|
|
461
|
-
this.username = _url.username;
|
|
462
|
-
this.password = _url.password;
|
|
463
|
-
this._hostname = _url.hostname;
|
|
464
|
-
this._port = _url.port;
|
|
465
|
-
this.pathname = _url.pathname;
|
|
466
|
-
this.search = _url.search;
|
|
467
|
-
this.hash = _url.hash;
|
|
468
|
-
}
|
|
469
|
-
toString() {
|
|
470
|
-
return this.href;
|
|
471
|
-
}
|
|
472
|
-
toJSON() {
|
|
473
|
-
return this.href;
|
|
474
|
-
}
|
|
475
|
-
get [Symbol.toStringTag]() {
|
|
476
|
-
return "URL";
|
|
477
|
-
}
|
|
478
|
-
[kNodeInspect]() {
|
|
479
|
-
return this.href;
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
Object.setPrototypeOf(_URL.prototype, globalThis.URL.prototype);
|
|
483
|
-
return _URL;
|
|
484
|
-
})();
|
|
485
|
-
function parsePath(input) {
|
|
486
|
-
const url = (input || "/").replace(/\\/g, "/");
|
|
487
|
-
const qIndex = url.indexOf("?");
|
|
488
|
-
if (qIndex === -1) {
|
|
489
|
-
return [url, ""];
|
|
490
|
-
}
|
|
491
|
-
return [url.slice(0, qIndex), url.slice(qIndex)];
|
|
492
|
-
}
|
|
493
|
-
function parseHost(host) {
|
|
494
|
-
const s = (host || "").split(":");
|
|
495
|
-
return [s[0], String(Number.parseInt(s[1]) || "")];
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
const NodeRequest = /* @__PURE__ */ (() => {
|
|
499
|
-
const _Request = class Request {
|
|
500
|
-
#url;
|
|
501
|
-
#headers;
|
|
502
|
-
#bodyUsed = false;
|
|
503
|
-
#abortSignal;
|
|
504
|
-
#hasBody;
|
|
505
|
-
#bodyBytes;
|
|
506
|
-
#blobBody;
|
|
507
|
-
#formDataBody;
|
|
508
|
-
#jsonBody;
|
|
509
|
-
#textBody;
|
|
510
|
-
#bodyStream;
|
|
511
|
-
constructor(nodeCtx) {
|
|
512
|
-
this._node = nodeCtx;
|
|
513
|
-
this.runtime = {
|
|
514
|
-
name: "node",
|
|
515
|
-
node: nodeCtx
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
get ip() {
|
|
519
|
-
return this._node.req.socket?.remoteAddress;
|
|
520
|
-
}
|
|
521
|
-
get headers() {
|
|
522
|
-
if (!this.#headers) {
|
|
523
|
-
this.#headers = new NodeRequestHeaders(this._node);
|
|
524
|
-
}
|
|
525
|
-
return this.#headers;
|
|
526
|
-
}
|
|
527
|
-
clone() {
|
|
528
|
-
return new _Request({ ...this._node });
|
|
529
|
-
}
|
|
530
|
-
get _url() {
|
|
531
|
-
if (!this.#url) {
|
|
532
|
-
this.#url = new NodeRequestURL(this._node);
|
|
533
|
-
}
|
|
534
|
-
return this.#url;
|
|
535
|
-
}
|
|
536
|
-
get url() {
|
|
537
|
-
return this._url.href;
|
|
538
|
-
}
|
|
539
|
-
get method() {
|
|
540
|
-
return this._node.req.method || "GET";
|
|
541
|
-
}
|
|
542
|
-
get signal() {
|
|
543
|
-
if (!this.#abortSignal) {
|
|
544
|
-
this.#abortSignal = new AbortController();
|
|
545
|
-
}
|
|
546
|
-
return this.#abortSignal.signal;
|
|
547
|
-
}
|
|
548
|
-
get bodyUsed() {
|
|
549
|
-
return this.#bodyUsed;
|
|
550
|
-
}
|
|
551
|
-
get _hasBody() {
|
|
552
|
-
if (this.#hasBody !== void 0) {
|
|
553
|
-
return this.#hasBody;
|
|
554
|
-
}
|
|
555
|
-
const method = this._node.req.method?.toUpperCase();
|
|
556
|
-
if (!method || !(method === "PATCH" || method === "POST" || method === "PUT" || method === "DELETE")) {
|
|
557
|
-
this.#hasBody = false;
|
|
558
|
-
return false;
|
|
559
|
-
}
|
|
560
|
-
if (!Number.parseInt(this._node.req.headers["content-length"] || "")) {
|
|
561
|
-
const isChunked = (this._node.req.headers["transfer-encoding"] || "").split(",").map((e) => e.trim()).filter(Boolean).includes("chunked");
|
|
562
|
-
if (!isChunked) {
|
|
563
|
-
this.#hasBody = false;
|
|
564
|
-
return false;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
this.#hasBody = true;
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
get body() {
|
|
571
|
-
if (!this._hasBody) {
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
if (!this.#bodyStream) {
|
|
575
|
-
this.#bodyUsed = true;
|
|
576
|
-
this.#bodyStream = new ReadableStream({
|
|
577
|
-
start: (controller) => {
|
|
578
|
-
this._node.req.on("data", (chunk) => {
|
|
579
|
-
controller.enqueue(chunk);
|
|
580
|
-
}).once("error", (error) => {
|
|
581
|
-
controller.error(error);
|
|
582
|
-
this.#abortSignal?.abort();
|
|
583
|
-
}).once("close", () => {
|
|
584
|
-
this.#abortSignal?.abort();
|
|
585
|
-
}).once("end", () => {
|
|
586
|
-
controller.close();
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
return this.#bodyStream;
|
|
592
|
-
}
|
|
593
|
-
bytes() {
|
|
594
|
-
if (!this.#bodyBytes) {
|
|
595
|
-
const _bodyStream = this.body;
|
|
596
|
-
this.#bodyBytes = _bodyStream ? _readStream(_bodyStream) : Promise.resolve(new Uint8Array());
|
|
597
|
-
}
|
|
598
|
-
return this.#bodyBytes;
|
|
599
|
-
}
|
|
600
|
-
arrayBuffer() {
|
|
601
|
-
return this.bytes().then((buff) => {
|
|
602
|
-
return buff.buffer.slice(
|
|
603
|
-
buff.byteOffset,
|
|
604
|
-
buff.byteOffset + buff.byteLength
|
|
605
|
-
);
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
blob() {
|
|
609
|
-
if (!this.#blobBody) {
|
|
610
|
-
this.#blobBody = this.bytes().then((bytes) => {
|
|
611
|
-
return new Blob([bytes], {
|
|
612
|
-
type: this._node.req.headers["content-type"]
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
return this.#blobBody;
|
|
617
|
-
}
|
|
618
|
-
formData() {
|
|
619
|
-
if (!this.#formDataBody) {
|
|
620
|
-
this.#formDataBody = new Response(this.body, {
|
|
621
|
-
headers: this.headers
|
|
622
|
-
}).formData();
|
|
623
|
-
}
|
|
624
|
-
return this.#formDataBody;
|
|
625
|
-
}
|
|
626
|
-
text() {
|
|
627
|
-
if (!this.#textBody) {
|
|
628
|
-
this.#textBody = this.bytes().then((bytes) => {
|
|
629
|
-
return new TextDecoder().decode(bytes);
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
return this.#textBody;
|
|
633
|
-
}
|
|
634
|
-
json() {
|
|
635
|
-
if (!this.#jsonBody) {
|
|
636
|
-
this.#jsonBody = this.text().then((txt) => {
|
|
637
|
-
return JSON.parse(txt);
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
return this.#jsonBody;
|
|
641
|
-
}
|
|
642
|
-
get [Symbol.toStringTag]() {
|
|
643
|
-
return "Request";
|
|
644
|
-
}
|
|
645
|
-
[kNodeInspect]() {
|
|
646
|
-
return {
|
|
647
|
-
method: this.method,
|
|
648
|
-
url: this.url,
|
|
649
|
-
headers: this.headers
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
};
|
|
653
|
-
Object.setPrototypeOf(_Request.prototype, globalThis.Request.prototype);
|
|
654
|
-
return _Request;
|
|
655
|
-
})();
|
|
656
|
-
async function _readStream(stream) {
|
|
657
|
-
const chunks = [];
|
|
658
|
-
await stream.pipeTo(
|
|
659
|
-
new WritableStream({
|
|
660
|
-
write(chunk) {
|
|
661
|
-
chunks.push(chunk);
|
|
662
|
-
}
|
|
663
|
-
})
|
|
664
|
-
);
|
|
665
|
-
return Buffer.concat(chunks);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
const NodeResponse = /* @__PURE__ */ (() => {
|
|
669
|
-
const CONTENT_TYPE = "content-type";
|
|
670
|
-
const JSON_TYPE = "application/json";
|
|
671
|
-
const JSON_HEADER = [[CONTENT_TYPE, JSON_TYPE]];
|
|
672
|
-
const _Response = class Response {
|
|
673
|
-
#body;
|
|
674
|
-
#init;
|
|
675
|
-
constructor(body, init) {
|
|
676
|
-
this.#body = body;
|
|
677
|
-
this.#init = init;
|
|
678
|
-
}
|
|
679
|
-
static json(data, init) {
|
|
680
|
-
if (init?.headers) {
|
|
681
|
-
if (!init.headers[CONTENT_TYPE]) {
|
|
682
|
-
const initHeaders = new Headers(init.headers);
|
|
683
|
-
if (!initHeaders.has(CONTENT_TYPE)) {
|
|
684
|
-
initHeaders.set(CONTENT_TYPE, JSON_TYPE);
|
|
685
|
-
}
|
|
686
|
-
init = { ...init, headers: initHeaders };
|
|
687
|
-
}
|
|
688
|
-
} else {
|
|
689
|
-
init = init ? { ...init } : {};
|
|
690
|
-
init.headers = JSON_HEADER;
|
|
691
|
-
}
|
|
692
|
-
return new _Response(JSON.stringify(data), init);
|
|
693
|
-
}
|
|
694
|
-
static error() {
|
|
695
|
-
return globalThis.Response.error();
|
|
696
|
-
}
|
|
697
|
-
static redirect(url, status) {
|
|
698
|
-
return globalThis.Response.redirect(url, status);
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Prepare Node.js response object
|
|
702
|
-
*/
|
|
703
|
-
nodeResponse() {
|
|
704
|
-
const status = this.#init?.status ?? 200;
|
|
705
|
-
const statusText = this.#init?.statusText ?? "";
|
|
706
|
-
const headers = [];
|
|
707
|
-
const headersInit = this.#init?.headers;
|
|
708
|
-
if (headersInit) {
|
|
709
|
-
const headerEntries = Array.isArray(headersInit) ? headersInit : headersInit.entries ? headersInit.entries() : Object.entries(headersInit);
|
|
710
|
-
for (const [key, value] of headerEntries) {
|
|
711
|
-
if (key === "set-cookie") {
|
|
712
|
-
for (const setCookie of splitSetCookieString(value)) {
|
|
713
|
-
headers.push(["set-cookie", setCookie]);
|
|
714
|
-
}
|
|
715
|
-
} else {
|
|
716
|
-
headers.push([key, value]);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if (this.#headersObj) {
|
|
721
|
-
for (const [key, value] of this.#headersObj) {
|
|
722
|
-
if (key === "set-cookie") {
|
|
723
|
-
for (const setCookie of splitSetCookieString(value)) {
|
|
724
|
-
headers.push(["set-cookie", setCookie]);
|
|
725
|
-
}
|
|
726
|
-
} else {
|
|
727
|
-
headers.push([key, value]);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
const bodyInit = this.#body;
|
|
732
|
-
let body;
|
|
733
|
-
if (bodyInit) {
|
|
734
|
-
if (typeof bodyInit === "string") {
|
|
735
|
-
body = bodyInit;
|
|
736
|
-
} else if (bodyInit instanceof ReadableStream) {
|
|
737
|
-
body = bodyInit;
|
|
738
|
-
} else if (bodyInit instanceof ArrayBuffer) {
|
|
739
|
-
body = Buffer.from(bodyInit);
|
|
740
|
-
} else if (bodyInit instanceof Uint8Array) {
|
|
741
|
-
body = Buffer.from(bodyInit);
|
|
742
|
-
} else if (bodyInit instanceof DataView) {
|
|
743
|
-
body = Buffer.from(bodyInit.buffer);
|
|
744
|
-
} else if (bodyInit instanceof Blob) {
|
|
745
|
-
body = bodyInit.stream();
|
|
746
|
-
if (bodyInit.type) {
|
|
747
|
-
headers.push(["content-type", bodyInit.type]);
|
|
748
|
-
}
|
|
749
|
-
} else if (typeof bodyInit.pipe === "function") {
|
|
750
|
-
body = bodyInit;
|
|
751
|
-
} else {
|
|
752
|
-
const res = new globalThis.Response(bodyInit);
|
|
753
|
-
body = res.body;
|
|
754
|
-
for (const [key, value] of res.headers) {
|
|
755
|
-
headers.push([key, value]);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
this.#body = void 0;
|
|
760
|
-
this.#init = void 0;
|
|
761
|
-
return {
|
|
762
|
-
status,
|
|
763
|
-
statusText,
|
|
764
|
-
headers,
|
|
765
|
-
body
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
// ... the rest is for interface compatibility only and usually not to be used ...
|
|
769
|
-
/** Lazy initialized response instance */
|
|
770
|
-
#responseObj;
|
|
771
|
-
/** Lazy initialized headers instance */
|
|
772
|
-
#headersObj;
|
|
773
|
-
clone() {
|
|
774
|
-
if (this.#responseObj) {
|
|
775
|
-
return this.#responseObj.clone();
|
|
776
|
-
}
|
|
777
|
-
return new globalThis.Response(this.#body, this.#init);
|
|
778
|
-
}
|
|
779
|
-
get #response() {
|
|
780
|
-
if (!this.#responseObj) {
|
|
781
|
-
this.#responseObj = new globalThis.Response(this.#body, this.#init);
|
|
782
|
-
this.#body = void 0;
|
|
783
|
-
this.#init = void 0;
|
|
784
|
-
this.#headersObj = void 0;
|
|
785
|
-
}
|
|
786
|
-
return this.#responseObj;
|
|
787
|
-
}
|
|
788
|
-
get headers() {
|
|
789
|
-
if (this.#responseObj) {
|
|
790
|
-
return this.#responseObj.headers;
|
|
791
|
-
}
|
|
792
|
-
if (!this.#headersObj) {
|
|
793
|
-
this.#headersObj = new Headers(this.#init?.headers);
|
|
794
|
-
}
|
|
795
|
-
return this.#headersObj;
|
|
796
|
-
}
|
|
797
|
-
get ok() {
|
|
798
|
-
if (this.#responseObj) {
|
|
799
|
-
return this.#responseObj.ok;
|
|
800
|
-
}
|
|
801
|
-
const status = this.#init?.status ?? 200;
|
|
802
|
-
return status >= 200 && status < 300;
|
|
803
|
-
}
|
|
804
|
-
get redirected() {
|
|
805
|
-
if (this.#responseObj) {
|
|
806
|
-
return this.#responseObj.redirected;
|
|
807
|
-
}
|
|
808
|
-
return false;
|
|
809
|
-
}
|
|
810
|
-
get status() {
|
|
811
|
-
if (this.#responseObj) {
|
|
812
|
-
return this.#responseObj.status;
|
|
813
|
-
}
|
|
814
|
-
return this.#init?.status ?? 200;
|
|
815
|
-
}
|
|
816
|
-
get statusText() {
|
|
817
|
-
if (this.#responseObj) {
|
|
818
|
-
return this.#responseObj.statusText;
|
|
819
|
-
}
|
|
820
|
-
return this.#init?.statusText ?? "";
|
|
821
|
-
}
|
|
822
|
-
get type() {
|
|
823
|
-
if (this.#responseObj) {
|
|
824
|
-
return this.#responseObj.type;
|
|
825
|
-
}
|
|
826
|
-
return "default";
|
|
827
|
-
}
|
|
828
|
-
get url() {
|
|
829
|
-
if (this.#responseObj) {
|
|
830
|
-
return this.#responseObj.url;
|
|
831
|
-
}
|
|
832
|
-
return "";
|
|
833
|
-
}
|
|
834
|
-
// --- body ---
|
|
835
|
-
#fastBody(as) {
|
|
836
|
-
const bodyInit = this.#body;
|
|
837
|
-
if (bodyInit === null || bodyInit === void 0) {
|
|
838
|
-
return null;
|
|
839
|
-
}
|
|
840
|
-
if (bodyInit instanceof as) {
|
|
841
|
-
return bodyInit;
|
|
842
|
-
}
|
|
843
|
-
return false;
|
|
844
|
-
}
|
|
845
|
-
get body() {
|
|
846
|
-
if (this.#responseObj) {
|
|
847
|
-
return this.#responseObj.body;
|
|
848
|
-
}
|
|
849
|
-
const fastBody = this.#fastBody(ReadableStream);
|
|
850
|
-
if (fastBody !== false) {
|
|
851
|
-
return fastBody;
|
|
852
|
-
}
|
|
853
|
-
return this.#response.body;
|
|
854
|
-
}
|
|
855
|
-
get bodyUsed() {
|
|
856
|
-
if (this.#responseObj) {
|
|
857
|
-
return this.#responseObj.bodyUsed;
|
|
858
|
-
}
|
|
859
|
-
return false;
|
|
860
|
-
}
|
|
861
|
-
arrayBuffer() {
|
|
862
|
-
if (this.#responseObj) {
|
|
863
|
-
return this.#responseObj.arrayBuffer();
|
|
864
|
-
}
|
|
865
|
-
const fastBody = this.#fastBody(ArrayBuffer);
|
|
866
|
-
if (fastBody !== false) {
|
|
867
|
-
return Promise.resolve(fastBody || new ArrayBuffer(0));
|
|
868
|
-
}
|
|
869
|
-
return this.#response.arrayBuffer();
|
|
870
|
-
}
|
|
871
|
-
blob() {
|
|
872
|
-
if (this.#responseObj) {
|
|
873
|
-
return this.#responseObj.blob();
|
|
874
|
-
}
|
|
875
|
-
const fastBody = this.#fastBody(Blob);
|
|
876
|
-
if (fastBody !== false) {
|
|
877
|
-
return Promise.resolve(fastBody || new Blob());
|
|
878
|
-
}
|
|
879
|
-
return this.#response.blob();
|
|
880
|
-
}
|
|
881
|
-
bytes() {
|
|
882
|
-
if (this.#responseObj) {
|
|
883
|
-
return this.#responseObj.bytes();
|
|
884
|
-
}
|
|
885
|
-
const fastBody = this.#fastBody(Uint8Array);
|
|
886
|
-
if (fastBody !== false) {
|
|
887
|
-
return Promise.resolve(fastBody || new Uint8Array());
|
|
888
|
-
}
|
|
889
|
-
return this.#response.bytes();
|
|
890
|
-
}
|
|
891
|
-
formData() {
|
|
892
|
-
if (this.#responseObj) {
|
|
893
|
-
return this.#responseObj.formData();
|
|
894
|
-
}
|
|
895
|
-
const fastBody = this.#fastBody(FormData);
|
|
896
|
-
if (fastBody !== false) {
|
|
897
|
-
return Promise.resolve(fastBody || new FormData());
|
|
898
|
-
}
|
|
899
|
-
return this.#response.formData();
|
|
900
|
-
}
|
|
901
|
-
text() {
|
|
902
|
-
if (this.#responseObj) {
|
|
903
|
-
return this.#responseObj.text();
|
|
904
|
-
}
|
|
905
|
-
const bodyInit = this.#body;
|
|
906
|
-
if (bodyInit === null || bodyInit === void 0) {
|
|
907
|
-
return Promise.resolve("");
|
|
908
|
-
}
|
|
909
|
-
if (typeof bodyInit === "string") {
|
|
910
|
-
return Promise.resolve(bodyInit);
|
|
911
|
-
}
|
|
912
|
-
return this.#response.text();
|
|
913
|
-
}
|
|
914
|
-
json() {
|
|
915
|
-
if (this.#responseObj) {
|
|
916
|
-
return this.#responseObj.json();
|
|
917
|
-
}
|
|
918
|
-
return this.text().then((text) => JSON.parse(text));
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
Object.setPrototypeOf(_Response.prototype, globalThis.Response.prototype);
|
|
922
|
-
return _Response;
|
|
923
|
-
})();
|
|
924
|
-
|
|
925
|
-
function serve(options) {
|
|
926
|
-
return new NodeServer(options);
|
|
927
|
-
}
|
|
928
|
-
function toNodeHandler(fetchHandler) {
|
|
929
|
-
return (nodeReq, nodeRes) => {
|
|
930
|
-
const request = new NodeRequest({ req: nodeReq, res: nodeRes });
|
|
931
|
-
const res = fetchHandler(request);
|
|
932
|
-
return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
class NodeServer {
|
|
936
|
-
constructor(options) {
|
|
937
|
-
this.runtime = "node";
|
|
938
|
-
this.options = options;
|
|
939
|
-
const fetchHandler = this.fetch = wrapFetch(this, [errorPlugin]);
|
|
940
|
-
const handler = (nodeReq, nodeRes) => {
|
|
941
|
-
const request = new NodeRequest({ req: nodeReq, res: nodeRes });
|
|
942
|
-
const res = fetchHandler(request);
|
|
943
|
-
return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
|
|
944
|
-
};
|
|
945
|
-
const tls = resolveTLSOptions(this.options);
|
|
946
|
-
const { port, hostname: host } = resolvePortAndHost(this.options);
|
|
947
|
-
this.serveOptions = {
|
|
948
|
-
port,
|
|
949
|
-
host,
|
|
950
|
-
exclusive: !this.options.reusePort,
|
|
951
|
-
...tls ? { cert: tls.cert, key: tls.key, passphrase: tls.passphrase } : {},
|
|
952
|
-
...this.options.node
|
|
953
|
-
};
|
|
954
|
-
const server = this.serveOptions.cert ? NodeHttps.createServer(
|
|
955
|
-
this.serveOptions,
|
|
956
|
-
handler
|
|
957
|
-
) : NodeHttp.createServer(this.serveOptions, handler);
|
|
958
|
-
const upgradeHandler = this.options.upgrade;
|
|
959
|
-
if (upgradeHandler) {
|
|
960
|
-
server.on("upgrade", (nodeReq, socket, header) => {
|
|
961
|
-
const request = new NodeRequest({
|
|
962
|
-
req: nodeReq,
|
|
963
|
-
upgrade: { socket, header }
|
|
964
|
-
});
|
|
965
|
-
const res = upgradeHandler(request);
|
|
966
|
-
return res instanceof Promise ? res.then(
|
|
967
|
-
(resolvedRes) => sendNodeUpgradeResponse(socket, resolvedRes)
|
|
968
|
-
) : sendNodeUpgradeResponse(socket, res);
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
this.node = { server, handler };
|
|
972
|
-
if (!options.manual) {
|
|
973
|
-
this.serve();
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
#listeningPromise;
|
|
977
|
-
serve() {
|
|
978
|
-
if (this.#listeningPromise) {
|
|
979
|
-
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
980
|
-
}
|
|
981
|
-
this.#listeningPromise = new Promise((resolve) => {
|
|
982
|
-
this.node.server.listen(this.serveOptions, () => {
|
|
983
|
-
printListening(this.options, this.url);
|
|
984
|
-
resolve();
|
|
985
|
-
});
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
get url() {
|
|
989
|
-
const addr = this.node?.server?.address();
|
|
990
|
-
if (!addr) {
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
return typeof addr === "string" ? addr : fmtURL(
|
|
994
|
-
addr.address,
|
|
995
|
-
addr.port,
|
|
996
|
-
this.node.server instanceof NodeHttps.Server
|
|
997
|
-
);
|
|
998
|
-
}
|
|
999
|
-
ready() {
|
|
1000
|
-
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
1001
|
-
}
|
|
1002
|
-
close(closeAll) {
|
|
1003
|
-
return new Promise((resolve, reject) => {
|
|
1004
|
-
if (closeAll) {
|
|
1005
|
-
this.node?.server?.closeAllConnections?.();
|
|
1006
|
-
}
|
|
1007
|
-
this.node?.server?.close(
|
|
1008
|
-
(error) => error ? reject(error) : resolve()
|
|
1009
|
-
);
|
|
1010
|
-
});
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
export { NodeResponse as FastResponse, NodeRequest, NodeRequestHeaders, NodeResponse, NodeResponseHeaders, serve, toNodeHandler };
|