srvx 0.2.6 → 0.2.7
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/adapters/bun.d.mts +3 -3
- package/dist/adapters/node.d.mts +3 -3
- package/dist/adapters/node.mjs +198 -176
- package/dist/types.d.mts +2 -2
- package/package.json +10 -7
package/dist/adapters/bun.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerOptions, Server,
|
|
1
|
+
import { ServerOptions, Server, BunFetchHandler } from '../types.mjs';
|
|
2
2
|
import * as Bun from 'bun';
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import 'node:https';
|
|
@@ -13,12 +13,12 @@ declare const Response: {
|
|
|
13
13
|
redirect(url: string | URL, status?: number): Response;
|
|
14
14
|
};
|
|
15
15
|
declare function serve(options: ServerOptions): BunServer;
|
|
16
|
-
declare class BunServer implements Server<
|
|
16
|
+
declare class BunServer implements Server<BunFetchHandler> {
|
|
17
17
|
readonly runtime = "bun";
|
|
18
18
|
readonly options: ServerOptions;
|
|
19
19
|
readonly bun: Server["bun"];
|
|
20
20
|
readonly serveOptions: Bun.ServeOptions | Bun.TLSServeOptions;
|
|
21
|
-
readonly fetch:
|
|
21
|
+
readonly fetch: BunFetchHandler;
|
|
22
22
|
constructor(options: ServerOptions);
|
|
23
23
|
serve(): Promise<Awaited<this>>;
|
|
24
24
|
get url(): string | undefined;
|
package/dist/adapters/node.d.mts
CHANGED
|
@@ -26,11 +26,11 @@ declare const NodeFastResponse: {
|
|
|
26
26
|
body: string | Uint8Array<ArrayBufferLike> | ReadableStream<Uint8Array<ArrayBufferLike>> | Readable | Buffer<ArrayBufferLike> | DataView<ArrayBufferLike> | null | undefined;
|
|
27
27
|
};
|
|
28
28
|
/** Lazy initialized response instance */
|
|
29
|
-
"__#4363@#responseObj"?: Response;
|
|
29
|
+
"__#4363@#responseObj"?: globalThis.Response;
|
|
30
30
|
/** Lazy initialized headers instance */
|
|
31
31
|
"__#4363@#headersObj"?: Headers;
|
|
32
|
-
clone(): Response;
|
|
33
|
-
readonly "__#4363@#response": Response;
|
|
32
|
+
clone(): globalThis.Response;
|
|
33
|
+
readonly "__#4363@#response": globalThis.Response;
|
|
34
34
|
readonly headers: Headers;
|
|
35
35
|
readonly ok: boolean;
|
|
36
36
|
readonly redirected: boolean;
|
package/dist/adapters/node.mjs
CHANGED
|
@@ -89,19 +89,18 @@ function streamBody(stream, nodeRes) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
const kNodeReq = /* @__PURE__ */ Symbol.for("srvx.node.request");
|
|
93
92
|
const kNodeInspect = /* @__PURE__ */ Symbol.for(
|
|
94
93
|
"nodejs.util.inspect.custom"
|
|
95
94
|
);
|
|
96
95
|
|
|
97
96
|
const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
98
|
-
class
|
|
99
|
-
constructor(
|
|
100
|
-
this
|
|
97
|
+
const _Headers = class Headers {
|
|
98
|
+
constructor(nodeCtx) {
|
|
99
|
+
this.node = nodeCtx;
|
|
101
100
|
}
|
|
102
101
|
append(name, value) {
|
|
103
102
|
name = name.toLowerCase();
|
|
104
|
-
const _headers = this
|
|
103
|
+
const _headers = this.node.req.headers;
|
|
105
104
|
const _current = _headers[name];
|
|
106
105
|
if (_current) {
|
|
107
106
|
if (Array.isArray(_current)) {
|
|
@@ -115,14 +114,14 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
115
114
|
}
|
|
116
115
|
delete(name) {
|
|
117
116
|
name = name.toLowerCase();
|
|
118
|
-
this
|
|
117
|
+
this.node.req.headers[name] = void 0;
|
|
119
118
|
}
|
|
120
119
|
get(name) {
|
|
121
120
|
name = name.toLowerCase();
|
|
122
|
-
return _normalizeValue(this
|
|
121
|
+
return _normalizeValue(this.node.req.headers[name]);
|
|
123
122
|
}
|
|
124
123
|
getSetCookie() {
|
|
125
|
-
const setCookie = this
|
|
124
|
+
const setCookie = this.node.req.headers["set-cookie"];
|
|
126
125
|
if (!setCookie || setCookie.length === 0) {
|
|
127
126
|
return [];
|
|
128
127
|
}
|
|
@@ -130,11 +129,11 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
130
129
|
}
|
|
131
130
|
has(name) {
|
|
132
131
|
name = name.toLowerCase();
|
|
133
|
-
return !!this
|
|
132
|
+
return !!this.node.req.headers[name];
|
|
134
133
|
}
|
|
135
134
|
set(name, value) {
|
|
136
135
|
name = name.toLowerCase();
|
|
137
|
-
this
|
|
136
|
+
this.node.req.headers[name] = value;
|
|
138
137
|
}
|
|
139
138
|
get count() {
|
|
140
139
|
throw new Error("Method not implemented.");
|
|
@@ -143,7 +142,7 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
143
142
|
throw new Error("Method not implemented.");
|
|
144
143
|
}
|
|
145
144
|
toJSON() {
|
|
146
|
-
const _headers = this
|
|
145
|
+
const _headers = this.node.req.headers;
|
|
147
146
|
const result = {};
|
|
148
147
|
for (const key in _headers) {
|
|
149
148
|
if (_headers[key]) {
|
|
@@ -153,7 +152,7 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
153
152
|
return result;
|
|
154
153
|
}
|
|
155
154
|
forEach(cb, thisArg) {
|
|
156
|
-
const _headers = this
|
|
155
|
+
const _headers = this.node.req.headers;
|
|
157
156
|
for (const key in _headers) {
|
|
158
157
|
if (_headers[key]) {
|
|
159
158
|
cb.call(
|
|
@@ -166,24 +165,24 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
*entries() {
|
|
169
|
-
const _headers = this
|
|
168
|
+
const _headers = this.node.req.headers;
|
|
170
169
|
for (const key in _headers) {
|
|
171
170
|
yield [key, _normalizeValue(_headers[key])];
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
173
|
*keys() {
|
|
175
|
-
const keys = Object.keys(this
|
|
174
|
+
const keys = Object.keys(this.node.req.headers);
|
|
176
175
|
for (const key of keys) {
|
|
177
176
|
yield key;
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
179
|
*values() {
|
|
181
|
-
const values = Object.values(this
|
|
180
|
+
const values = Object.values(this.node.req.headers);
|
|
182
181
|
for (const value of values) {
|
|
183
182
|
yield _normalizeValue(value);
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
|
-
[
|
|
185
|
+
[Symbol.iterator]() {
|
|
187
186
|
return this.entries()[Symbol.iterator]();
|
|
188
187
|
}
|
|
189
188
|
get [Symbol.toStringTag]() {
|
|
@@ -192,9 +191,9 @@ const NodeReqHeadersProxy = /* @__PURE__ */ (() => {
|
|
|
192
191
|
[kNodeInspect]() {
|
|
193
192
|
return Object.fromEntries(this.entries());
|
|
194
193
|
}
|
|
195
|
-
}
|
|
196
|
-
Object.setPrototypeOf(
|
|
197
|
-
return
|
|
194
|
+
};
|
|
195
|
+
Object.setPrototypeOf(_Headers.prototype, globalThis.Headers.prototype);
|
|
196
|
+
return _Headers;
|
|
198
197
|
})();
|
|
199
198
|
function _normalizeValue(value) {
|
|
200
199
|
if (Array.isArray(value)) {
|
|
@@ -203,149 +202,171 @@ function _normalizeValue(value) {
|
|
|
203
202
|
return value || "";
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
const NodeReqURLProxy = /* @__PURE__ */ (() =>
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
205
|
+
const NodeReqURLProxy = /* @__PURE__ */ (() => {
|
|
206
|
+
const _URL = class URL {
|
|
207
|
+
constructor(nodeCtx) {
|
|
208
|
+
this._hash = "";
|
|
209
|
+
this._username = "";
|
|
210
|
+
this._password = "";
|
|
211
|
+
this.node = nodeCtx;
|
|
212
|
+
}
|
|
213
|
+
get hash() {
|
|
214
|
+
return this._hash;
|
|
215
|
+
}
|
|
216
|
+
set hash(value) {
|
|
217
|
+
this._hash = value;
|
|
218
|
+
}
|
|
219
|
+
get username() {
|
|
220
|
+
return this._username;
|
|
221
|
+
}
|
|
222
|
+
set username(value) {
|
|
223
|
+
this._username = value;
|
|
224
|
+
}
|
|
225
|
+
get password() {
|
|
226
|
+
return this._password;
|
|
227
|
+
}
|
|
228
|
+
set password(value) {
|
|
229
|
+
this._password = value;
|
|
230
|
+
}
|
|
231
|
+
// host
|
|
232
|
+
get host() {
|
|
233
|
+
return this.node.req.headers.host || "";
|
|
234
|
+
}
|
|
235
|
+
set host(value) {
|
|
236
|
+
this._hostname = void 0;
|
|
237
|
+
this._port = void 0;
|
|
238
|
+
this.node.req.headers.host = value;
|
|
239
|
+
}
|
|
240
|
+
// hostname
|
|
241
|
+
get hostname() {
|
|
242
|
+
if (this._hostname === void 0) {
|
|
243
|
+
const [hostname, port] = parseHost(this.node.req.headers.host);
|
|
244
|
+
if (this._port === void 0 && port) {
|
|
245
|
+
this._port = String(Number.parseInt(port) || "");
|
|
246
|
+
}
|
|
247
|
+
this._hostname = hostname || "localhost";
|
|
228
248
|
}
|
|
229
|
-
this._hostname
|
|
249
|
+
return this._hostname;
|
|
230
250
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this.
|
|
251
|
+
set hostname(value) {
|
|
252
|
+
this._hostname = value;
|
|
253
|
+
}
|
|
254
|
+
// port
|
|
255
|
+
get port() {
|
|
256
|
+
if (this._port === void 0) {
|
|
257
|
+
const [hostname, port] = parseHost(this.node.req.headers.host);
|
|
258
|
+
if (this._hostname === void 0 && hostname) {
|
|
259
|
+
this._hostname = hostname;
|
|
260
|
+
}
|
|
261
|
+
this._port = port || String(this.node.req.socket?.localPort || "");
|
|
242
262
|
}
|
|
243
|
-
this._port
|
|
263
|
+
return this._port;
|
|
244
264
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
265
|
+
set port(value) {
|
|
266
|
+
this._port = String(Number.parseInt(value) || "");
|
|
267
|
+
}
|
|
268
|
+
// pathname
|
|
269
|
+
get pathname() {
|
|
270
|
+
if (this._pathname === void 0) {
|
|
271
|
+
const [pathname, search] = parsePath(this.node.req.url || "/");
|
|
272
|
+
this._pathname = pathname;
|
|
273
|
+
if (this._search === void 0) {
|
|
274
|
+
this._search = search;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return this._pathname;
|
|
278
|
+
}
|
|
279
|
+
set pathname(value) {
|
|
280
|
+
if (value[0] !== "/") {
|
|
281
|
+
value = "/" + value;
|
|
282
|
+
}
|
|
283
|
+
if (value === this._pathname) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this._pathname = value;
|
|
287
|
+
this.node.req.url = value + this.search;
|
|
288
|
+
}
|
|
289
|
+
// search
|
|
290
|
+
get search() {
|
|
255
291
|
if (this._search === void 0) {
|
|
292
|
+
const [pathname, search] = parsePath(this.node.req.url || "/");
|
|
256
293
|
this._search = search;
|
|
294
|
+
if (this._pathname === void 0) {
|
|
295
|
+
this._pathname = pathname;
|
|
296
|
+
}
|
|
257
297
|
}
|
|
298
|
+
return this._search;
|
|
258
299
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
300
|
+
set search(value) {
|
|
301
|
+
if (value === "?") {
|
|
302
|
+
value = "";
|
|
303
|
+
} else if (value && value[0] !== "?") {
|
|
304
|
+
value = "?" + value;
|
|
305
|
+
}
|
|
306
|
+
if (value === this._search) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
this._search = value;
|
|
310
|
+
this._searchParams = void 0;
|
|
311
|
+
this.node.req.url = this.pathname + value;
|
|
264
312
|
}
|
|
265
|
-
|
|
266
|
-
|
|
313
|
+
// searchParams
|
|
314
|
+
get searchParams() {
|
|
315
|
+
if (!this._searchParams) {
|
|
316
|
+
this._searchParams = new URLSearchParams(this.search);
|
|
317
|
+
}
|
|
318
|
+
return this._searchParams;
|
|
267
319
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (this._pathname === void 0) {
|
|
277
|
-
this._pathname = pathname;
|
|
320
|
+
set searchParams(value) {
|
|
321
|
+
this._searchParams = value;
|
|
322
|
+
this._search = value.toString();
|
|
323
|
+
}
|
|
324
|
+
// protocol
|
|
325
|
+
get protocol() {
|
|
326
|
+
if (!this._protocol) {
|
|
327
|
+
this._protocol = this.node.req.socket?.encrypted || this.node.req.headers["x-forwarded-proto"] === "https" ? "https:" : "http:";
|
|
278
328
|
}
|
|
329
|
+
return this._protocol;
|
|
279
330
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
set search(value) {
|
|
283
|
-
if (value === "?") {
|
|
284
|
-
value = "";
|
|
285
|
-
} else if (value && value[0] !== "?") {
|
|
286
|
-
value = "?" + value;
|
|
331
|
+
set protocol(value) {
|
|
332
|
+
this._protocol = value;
|
|
287
333
|
}
|
|
288
|
-
|
|
289
|
-
|
|
334
|
+
// origin
|
|
335
|
+
get origin() {
|
|
336
|
+
return `${this.protocol}//${this.host}`;
|
|
290
337
|
}
|
|
291
|
-
|
|
292
|
-
this._searchParams = void 0;
|
|
293
|
-
this[kNodeReq].url = this.pathname + value;
|
|
294
|
-
}
|
|
295
|
-
// searchParams
|
|
296
|
-
get searchParams() {
|
|
297
|
-
if (!this._searchParams) {
|
|
298
|
-
this._searchParams = new URLSearchParams(this.search);
|
|
338
|
+
set origin(_value) {
|
|
299
339
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this._searchParams = value;
|
|
304
|
-
this._search = value.toString();
|
|
305
|
-
}
|
|
306
|
-
// protocol
|
|
307
|
-
get protocol() {
|
|
308
|
-
if (!this._protocol) {
|
|
309
|
-
this._protocol = this[kNodeReq].socket?.encrypted || this[kNodeReq].headers["x-forwarded-proto"] === "https" ? "https:" : "http:";
|
|
340
|
+
// href
|
|
341
|
+
get href() {
|
|
342
|
+
return `${this.protocol}//${this.host}${this.pathname}${this.search}`;
|
|
310
343
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
toString() {
|
|
338
|
-
return this.href;
|
|
339
|
-
}
|
|
340
|
-
toJSON() {
|
|
341
|
-
return this.href;
|
|
342
|
-
}
|
|
343
|
-
get [(Symbol.toStringTag)]() {
|
|
344
|
-
return "URL";
|
|
345
|
-
}
|
|
346
|
-
[kNodeInspect]() {
|
|
347
|
-
return this.href;
|
|
348
|
-
}
|
|
344
|
+
set href(value) {
|
|
345
|
+
const _url = new globalThis.URL(value);
|
|
346
|
+
this._protocol = _url.protocol;
|
|
347
|
+
this.username = _url.username;
|
|
348
|
+
this.password = _url.password;
|
|
349
|
+
this._hostname = _url.hostname;
|
|
350
|
+
this._port = _url.port;
|
|
351
|
+
this.pathname = _url.pathname;
|
|
352
|
+
this.search = _url.search;
|
|
353
|
+
this.hash = _url.hash;
|
|
354
|
+
}
|
|
355
|
+
toString() {
|
|
356
|
+
return this.href;
|
|
357
|
+
}
|
|
358
|
+
toJSON() {
|
|
359
|
+
return this.href;
|
|
360
|
+
}
|
|
361
|
+
get [Symbol.toStringTag]() {
|
|
362
|
+
return "URL";
|
|
363
|
+
}
|
|
364
|
+
[kNodeInspect]() {
|
|
365
|
+
return this.href;
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
Object.setPrototypeOf(_URL.prototype, globalThis.URL.prototype);
|
|
369
|
+
return _URL;
|
|
349
370
|
})();
|
|
350
371
|
function parsePath(input) {
|
|
351
372
|
const url = (input || "/").replace(/\\/g, "/");
|
|
@@ -361,7 +382,7 @@ function parseHost(host) {
|
|
|
361
382
|
}
|
|
362
383
|
|
|
363
384
|
const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
364
|
-
class
|
|
385
|
+
const _Request = class Request {
|
|
365
386
|
#url;
|
|
366
387
|
#headers;
|
|
367
388
|
#bodyUsed = false;
|
|
@@ -373,29 +394,32 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
373
394
|
#jsonBody;
|
|
374
395
|
#textBody;
|
|
375
396
|
#bodyStream;
|
|
376
|
-
constructor(
|
|
377
|
-
this
|
|
397
|
+
constructor(nodeCtx) {
|
|
398
|
+
this.node = nodeCtx;
|
|
378
399
|
}
|
|
379
400
|
get headers() {
|
|
380
401
|
if (!this.#headers) {
|
|
381
|
-
this.#headers = new NodeReqHeadersProxy(this
|
|
402
|
+
this.#headers = new NodeReqHeadersProxy(this.node);
|
|
382
403
|
}
|
|
383
404
|
return this.#headers;
|
|
384
405
|
}
|
|
385
406
|
get remoteAddress() {
|
|
386
|
-
return this
|
|
407
|
+
return this.node.req.socket?.remoteAddress;
|
|
387
408
|
}
|
|
388
409
|
clone() {
|
|
389
|
-
return new
|
|
410
|
+
return new _Request({ ...this.node });
|
|
390
411
|
}
|
|
391
|
-
get
|
|
412
|
+
get _url() {
|
|
392
413
|
if (!this.#url) {
|
|
393
|
-
this.#url = new NodeReqURLProxy(this
|
|
414
|
+
this.#url = new NodeReqURLProxy(this.node);
|
|
394
415
|
}
|
|
395
|
-
return this.#url
|
|
416
|
+
return this.#url;
|
|
417
|
+
}
|
|
418
|
+
get url() {
|
|
419
|
+
return this._url.href;
|
|
396
420
|
}
|
|
397
421
|
get method() {
|
|
398
|
-
return this
|
|
422
|
+
return this.node.req.method || "GET";
|
|
399
423
|
}
|
|
400
424
|
get signal() {
|
|
401
425
|
if (!this.#abortSignal) {
|
|
@@ -410,13 +434,13 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
410
434
|
if (this.#hasBody !== void 0) {
|
|
411
435
|
return this.#hasBody;
|
|
412
436
|
}
|
|
413
|
-
const method = this
|
|
437
|
+
const method = this.node.req.method?.toUpperCase();
|
|
414
438
|
if (!method || !(method === "PATCH" || method === "POST" || method === "PUT" || method === "DELETE")) {
|
|
415
439
|
this.#hasBody = false;
|
|
416
440
|
return false;
|
|
417
441
|
}
|
|
418
|
-
if (!Number.parseInt(this
|
|
419
|
-
const isChunked = (this
|
|
442
|
+
if (!Number.parseInt(this.node.req.headers["content-length"] || "")) {
|
|
443
|
+
const isChunked = (this.node.req.headers["transfer-encoding"] || "").split(",").map((e) => e.trim()).filter(Boolean).includes("chunked");
|
|
420
444
|
if (!isChunked) {
|
|
421
445
|
this.#hasBody = false;
|
|
422
446
|
return false;
|
|
@@ -433,7 +457,7 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
433
457
|
this.#bodyUsed = true;
|
|
434
458
|
this.#bodyStream = new ReadableStream({
|
|
435
459
|
start: (controller) => {
|
|
436
|
-
this
|
|
460
|
+
this.node.req.on("data", (chunk) => {
|
|
437
461
|
controller.enqueue(chunk);
|
|
438
462
|
}).once("error", (error) => {
|
|
439
463
|
controller.error(error);
|
|
@@ -467,7 +491,7 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
467
491
|
if (!this.#blobBody) {
|
|
468
492
|
this.#blobBody = this.bytes().then((bytes) => {
|
|
469
493
|
return new Blob([bytes], {
|
|
470
|
-
type: this
|
|
494
|
+
type: this.node.req.headers["content-type"]
|
|
471
495
|
});
|
|
472
496
|
});
|
|
473
497
|
}
|
|
@@ -497,7 +521,7 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
497
521
|
}
|
|
498
522
|
return this.#jsonBody;
|
|
499
523
|
}
|
|
500
|
-
get [
|
|
524
|
+
get [Symbol.toStringTag]() {
|
|
501
525
|
return "Request";
|
|
502
526
|
}
|
|
503
527
|
[kNodeInspect]() {
|
|
@@ -507,9 +531,9 @@ const NodeRequestProxy = /* @__PURE__ */ (() => {
|
|
|
507
531
|
headers: this.headers
|
|
508
532
|
};
|
|
509
533
|
}
|
|
510
|
-
}
|
|
511
|
-
Object.setPrototypeOf(
|
|
512
|
-
return
|
|
534
|
+
};
|
|
535
|
+
Object.setPrototypeOf(_Request.prototype, globalThis.Request.prototype);
|
|
536
|
+
return _Request;
|
|
513
537
|
})();
|
|
514
538
|
async function _readStream(stream) {
|
|
515
539
|
const chunks = [];
|
|
@@ -524,7 +548,7 @@ async function _readStream(stream) {
|
|
|
524
548
|
}
|
|
525
549
|
|
|
526
550
|
const NodeFastResponse = /* @__PURE__ */ (() => {
|
|
527
|
-
class
|
|
551
|
+
const _Response = class Response {
|
|
528
552
|
#body;
|
|
529
553
|
#init;
|
|
530
554
|
constructor(body, init) {
|
|
@@ -572,7 +596,7 @@ const NodeFastResponse = /* @__PURE__ */ (() => {
|
|
|
572
596
|
} else if (typeof bodyInit.pipe === "function") {
|
|
573
597
|
body = bodyInit;
|
|
574
598
|
} else {
|
|
575
|
-
const res = new Response(bodyInit);
|
|
599
|
+
const res = new globalThis.Response(bodyInit);
|
|
576
600
|
body = res.body;
|
|
577
601
|
for (const [key, value] of res.headers) {
|
|
578
602
|
headers.push([key, value]);
|
|
@@ -597,11 +621,11 @@ const NodeFastResponse = /* @__PURE__ */ (() => {
|
|
|
597
621
|
if (this.#responseObj) {
|
|
598
622
|
return this.#responseObj.clone();
|
|
599
623
|
}
|
|
600
|
-
return new Response(this.#body, this.#init);
|
|
624
|
+
return new globalThis.Response(this.#body, this.#init);
|
|
601
625
|
}
|
|
602
626
|
get #response() {
|
|
603
627
|
if (!this.#responseObj) {
|
|
604
|
-
this.#responseObj = new Response(this.#body, this.#init);
|
|
628
|
+
this.#responseObj = new globalThis.Response(this.#body, this.#init);
|
|
605
629
|
this.#body = void 0;
|
|
606
630
|
this.#init = void 0;
|
|
607
631
|
this.#headersObj = void 0;
|
|
@@ -740,9 +764,9 @@ const NodeFastResponse = /* @__PURE__ */ (() => {
|
|
|
740
764
|
}
|
|
741
765
|
return this.text().then((text) => JSON.parse(text));
|
|
742
766
|
}
|
|
743
|
-
}
|
|
744
|
-
Object.setPrototypeOf(
|
|
745
|
-
return
|
|
767
|
+
};
|
|
768
|
+
Object.setPrototypeOf(_Response.prototype, globalThis.Response.prototype);
|
|
769
|
+
return _Response;
|
|
746
770
|
})();
|
|
747
771
|
|
|
748
772
|
function serve(options) {
|
|
@@ -750,8 +774,7 @@ function serve(options) {
|
|
|
750
774
|
}
|
|
751
775
|
function toNodeHandler(fetchHandler) {
|
|
752
776
|
return (nodeReq, nodeRes) => {
|
|
753
|
-
const request = new NodeRequestProxy(nodeReq);
|
|
754
|
-
request.node = { req: nodeReq, res: nodeRes };
|
|
777
|
+
const request = new NodeRequestProxy({ req: nodeReq, res: nodeRes });
|
|
755
778
|
const res = fetchHandler(request);
|
|
756
779
|
return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
|
|
757
780
|
};
|
|
@@ -763,8 +786,7 @@ class NodeServer {
|
|
|
763
786
|
const fetchHandler = wrapFetch(this, this.options.fetch);
|
|
764
787
|
this.fetch = fetchHandler;
|
|
765
788
|
const handler = (nodeReq, nodeRes) => {
|
|
766
|
-
const request = new NodeRequestProxy(nodeReq);
|
|
767
|
-
request.node = { req: nodeReq, res: nodeRes };
|
|
789
|
+
const request = new NodeRequestProxy({ req: nodeReq, res: nodeRes });
|
|
768
790
|
const res = fetchHandler(request);
|
|
769
791
|
return res instanceof Promise ? res.then((resolvedRes) => sendNodeResponse(nodeRes, resolvedRes)) : sendNodeResponse(nodeRes, res);
|
|
770
792
|
};
|
package/dist/types.d.mts
CHANGED
|
@@ -194,9 +194,9 @@ interface ServerRequest extends Request {
|
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
197
|
-
type
|
|
197
|
+
type BunFetchHandler = (request: Request, server?: Bun.Server) => Response | Promise<Response>;
|
|
198
198
|
type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
|
|
199
199
|
type NodeHttpHandler = (nodeReq: NodeHttp.IncomingMessage, nodeRes: NodeHttp.ServerResponse) => void | Promise<void>;
|
|
200
200
|
type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
|
|
201
201
|
|
|
202
|
-
export { type
|
|
202
|
+
export { type BunFetchHandler, type CloudflareFetchHandler, type DenoFetchHandler, type FetchHandler, type NodeHttpHandler, Response, type Server, type ServerHandler, type ServerOptions, type ServerPlugin, type ServerPluginInstance, type ServerRequest, serve };
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
|
|
5
5
|
"repository": "unjs/srvx",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"type": "module",
|
|
9
|
-
"types": "./dist/types.d.mts",
|
|
10
9
|
"exports": {
|
|
11
10
|
"./types": "./dist/types.d.mts",
|
|
12
11
|
"./deno": "./dist/adapters/deno.mjs",
|
|
@@ -21,6 +20,7 @@
|
|
|
21
20
|
"types": "./dist/types.d.mts"
|
|
22
21
|
}
|
|
23
22
|
},
|
|
23
|
+
"types": "./dist/types.d.mts",
|
|
24
24
|
"files": [
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"dev": "vitest dev",
|
|
31
31
|
"lint": "eslint . && prettier -c .",
|
|
32
32
|
"lint:fix": "automd && eslint . --fix && prettier -w .",
|
|
33
|
-
"
|
|
34
|
-
"play:node": "node playground/app.mjs",
|
|
35
|
-
"play:deno": "deno run -A playground/app.mjs",
|
|
33
|
+
"prepack": "pnpm build",
|
|
36
34
|
"play:bun": "bun playground/app.mjs",
|
|
37
35
|
"play:cf": "pnpx wrangler dev playground/app.mjs",
|
|
38
|
-
"
|
|
36
|
+
"play:deno": "deno run -A playground/app.mjs",
|
|
37
|
+
"play:mkcert": "openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt -days 365 -subj /CN=srvx.local",
|
|
38
|
+
"play:node": "node playground/app.mjs",
|
|
39
39
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
40
40
|
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
41
41
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
@@ -66,5 +66,8 @@
|
|
|
66
66
|
"unbuild": "^3.5.0",
|
|
67
67
|
"vitest": "^3.0.9"
|
|
68
68
|
},
|
|
69
|
-
"packageManager": "pnpm@10.6.5"
|
|
69
|
+
"packageManager": "pnpm@10.6.5",
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=20.11.1"
|
|
72
|
+
}
|
|
70
73
|
}
|