srvx 0.8.8 → 0.8.10
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/_chunks/_inherit-DLZfB57K.mjs +30 -0
- package/dist/_chunks/_url-BQeTFJZ1.d.mts +26 -0
- package/dist/_chunks/_url-Q_-LB8LX.mjs +117 -0
- package/dist/_chunks/{call-LB9MY5Dv.mjs → call-DYf04jcm.mjs} +2 -1
- package/dist/_chunks/{response-6LJL3Qlz.mjs → response-iYyldB4J.mjs} +3 -21
- package/dist/adapters/bun.d.mts +2 -2
- package/dist/adapters/bun.mjs +2 -1
- package/dist/adapters/cloudflare.d.mts +1 -1
- package/dist/adapters/cloudflare.mjs +1 -1
- package/dist/adapters/deno.d.mts +2 -2
- package/dist/adapters/deno.mjs +2 -1
- package/dist/adapters/generic.d.mts +1 -1
- package/dist/adapters/generic.mjs +1 -1
- package/dist/adapters/node.d.mts +2 -3
- package/dist/adapters/node.mjs +31 -169
- package/dist/adapters/service-worker.d.mts +1 -1
- package/dist/adapters/service-worker.mjs +1 -1
- package/dist/cli.mjs +27 -10
- package/dist/log.d.mts +1 -1
- package/dist/static.d.mts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +10 -10
- package/dist/_chunks/_url-CdE4ce6F.mjs +0 -91
- package/dist/_chunks/_url-D8u5OAto.d.mts +0 -13
- /package/dist/_chunks/{_plugins-DOhVIkXu.mjs → _plugins-DmMfurBQ.mjs} +0 -0
- /package/dist/_chunks/{types-BtByT9ny.d.mts → types-hx5EhU1U.d.mts} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/_inherit.ts
|
|
2
|
+
function lazyInherit(target, source, sourceKey) {
|
|
3
|
+
for (const key of Object.getOwnPropertyNames(source)) {
|
|
4
|
+
const targetDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
5
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
6
|
+
let modified = false;
|
|
7
|
+
if (desc.get) {
|
|
8
|
+
modified = true;
|
|
9
|
+
desc.get = targetDesc?.get || function() {
|
|
10
|
+
return this[sourceKey][key];
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
if (desc.set) {
|
|
14
|
+
modified = true;
|
|
15
|
+
desc.set = targetDesc?.set || function(value) {
|
|
16
|
+
this[sourceKey][key] = value;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (typeof desc.value === "function") {
|
|
20
|
+
modified = true;
|
|
21
|
+
desc.value = function(...args) {
|
|
22
|
+
return this[sourceKey][key](...args);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (modified) Object.defineProperty(target, key, desc);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { lazyInherit };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/_url.d.ts
|
|
2
|
+
type URLInit = {
|
|
3
|
+
protocol: string;
|
|
4
|
+
host: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
search: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* URL wrapper with fast paths to access to the following props:
|
|
10
|
+
*
|
|
11
|
+
* - `url.pathname`
|
|
12
|
+
* - `url.search`
|
|
13
|
+
* - `url.searchParams`
|
|
14
|
+
* - `url.protocol`
|
|
15
|
+
*
|
|
16
|
+
* **NOTES:**
|
|
17
|
+
*
|
|
18
|
+
* - It is assumed that the input URL is **already encoded** and formatted from an HTTP request and contains no hash.
|
|
19
|
+
* - Triggering the setters or getters on other props will deoptimize to full URL parsing.
|
|
20
|
+
* - Changes to `searchParams` will be discarded as we don't track them.
|
|
21
|
+
*/
|
|
22
|
+
declare const FastURL: {
|
|
23
|
+
new (url: string | URLInit): URL;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { FastURL as FastURL$2 };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { lazyInherit } from "./_inherit-DLZfB57K.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/_url.ts
|
|
4
|
+
/**
|
|
5
|
+
* URL wrapper with fast paths to access to the following props:
|
|
6
|
+
*
|
|
7
|
+
* - `url.pathname`
|
|
8
|
+
* - `url.search`
|
|
9
|
+
* - `url.searchParams`
|
|
10
|
+
* - `url.protocol`
|
|
11
|
+
*
|
|
12
|
+
* **NOTES:**
|
|
13
|
+
*
|
|
14
|
+
* - It is assumed that the input URL is **already encoded** and formatted from an HTTP request and contains no hash.
|
|
15
|
+
* - Triggering the setters or getters on other props will deoptimize to full URL parsing.
|
|
16
|
+
* - Changes to `searchParams` will be discarded as we don't track them.
|
|
17
|
+
*/
|
|
18
|
+
const FastURL = /* @__PURE__ */ (() => {
|
|
19
|
+
const NativeURL = globalThis.URL;
|
|
20
|
+
const FastURL$1 = class URL {
|
|
21
|
+
#url;
|
|
22
|
+
#href;
|
|
23
|
+
#protocol;
|
|
24
|
+
#host;
|
|
25
|
+
#pathname;
|
|
26
|
+
#search;
|
|
27
|
+
#searchParams;
|
|
28
|
+
#pos;
|
|
29
|
+
constructor(url) {
|
|
30
|
+
if (typeof url === "string") this.#href = url;
|
|
31
|
+
else {
|
|
32
|
+
this.#protocol = url.protocol;
|
|
33
|
+
this.#host = url.host;
|
|
34
|
+
this.#pathname = url.pathname;
|
|
35
|
+
this.#search = url.search;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get _url() {
|
|
39
|
+
if (this.#url) return this.#url;
|
|
40
|
+
this.#url = new NativeURL(this.href);
|
|
41
|
+
this.#href = void 0;
|
|
42
|
+
this.#protocol = void 0;
|
|
43
|
+
this.#host = void 0;
|
|
44
|
+
this.#pathname = void 0;
|
|
45
|
+
this.#search = void 0;
|
|
46
|
+
this.#searchParams = void 0;
|
|
47
|
+
this.#pos = void 0;
|
|
48
|
+
return this.#url;
|
|
49
|
+
}
|
|
50
|
+
get href() {
|
|
51
|
+
if (this.#url) return this.#url.href;
|
|
52
|
+
if (!this.#href) this.#href = `${this.#protocol || "http:"}//${this.#host || "localhost"}${this.#pathname || "/"}${this.#search || ""}`;
|
|
53
|
+
return this.#href;
|
|
54
|
+
}
|
|
55
|
+
#getPos() {
|
|
56
|
+
if (!this.#pos) {
|
|
57
|
+
const url = this.href;
|
|
58
|
+
const protoIndex = url.indexOf("://");
|
|
59
|
+
const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
|
|
60
|
+
const qIndex = pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex);
|
|
61
|
+
this.#pos = [
|
|
62
|
+
protoIndex,
|
|
63
|
+
pathnameIndex,
|
|
64
|
+
qIndex
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
return this.#pos;
|
|
68
|
+
}
|
|
69
|
+
get pathname() {
|
|
70
|
+
if (this.#url) return this.#url.pathname;
|
|
71
|
+
if (this.#pathname === void 0) {
|
|
72
|
+
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
73
|
+
if (pathnameIndex === -1) return this._url.pathname;
|
|
74
|
+
this.#pathname = this.href.slice(pathnameIndex, queryIndex === -1 ? void 0 : queryIndex);
|
|
75
|
+
}
|
|
76
|
+
return this.#pathname;
|
|
77
|
+
}
|
|
78
|
+
get search() {
|
|
79
|
+
if (this.#url) return this.#url.search;
|
|
80
|
+
if (this.#search === void 0) {
|
|
81
|
+
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
82
|
+
if (pathnameIndex === -1) return this._url.search;
|
|
83
|
+
const url = this.href;
|
|
84
|
+
this.#search = queryIndex === -1 || queryIndex === url.length - 1 ? "" : url.slice(queryIndex);
|
|
85
|
+
}
|
|
86
|
+
return this.#search;
|
|
87
|
+
}
|
|
88
|
+
get searchParams() {
|
|
89
|
+
if (this.#url) return this.#url.searchParams;
|
|
90
|
+
if (!this.#searchParams) this.#searchParams = new URLSearchParams(this.search);
|
|
91
|
+
return this.#searchParams;
|
|
92
|
+
}
|
|
93
|
+
get protocol() {
|
|
94
|
+
if (this.#url) return this.#url.protocol;
|
|
95
|
+
if (this.#protocol === void 0) {
|
|
96
|
+
const [protocolIndex] = this.#getPos();
|
|
97
|
+
if (protocolIndex === -1) return this._url.protocol;
|
|
98
|
+
const url = this.href;
|
|
99
|
+
this.#protocol = url.slice(0, protocolIndex + 1);
|
|
100
|
+
}
|
|
101
|
+
return this.#protocol;
|
|
102
|
+
}
|
|
103
|
+
toString() {
|
|
104
|
+
return this.href;
|
|
105
|
+
}
|
|
106
|
+
toJSON() {
|
|
107
|
+
return this.href;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
lazyInherit(FastURL$1.prototype, NativeURL.prototype, "_url");
|
|
111
|
+
Object.setPrototypeOf(FastURL$1.prototype, NativeURL.prototype);
|
|
112
|
+
Object.setPrototypeOf(FastURL$1, NativeURL);
|
|
113
|
+
return FastURL$1;
|
|
114
|
+
})();
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { FastURL as FastURL$1 };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./_inherit-DLZfB57K.mjs";
|
|
2
|
+
import { NodeResponse, NodeResponseHeaders } from "./response-iYyldB4J.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/adapters/_node/call.ts
|
|
4
5
|
function callNodeHandler(handler, req) {
|
|
@@ -1,26 +1,8 @@
|
|
|
1
|
+
import { lazyInherit } from "./_inherit-DLZfB57K.mjs";
|
|
1
2
|
import { splitSetCookieString } from "cookie-es";
|
|
2
3
|
|
|
3
4
|
//#region src/adapters/_node/_common.ts
|
|
4
5
|
const kNodeInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
5
|
-
function inheritProps(target, source, sourceKey) {
|
|
6
|
-
for (const key of Object.getOwnPropertyNames(source)) {
|
|
7
|
-
if (key in target) continue;
|
|
8
|
-
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
9
|
-
if (desc.get) Object.defineProperty(target, key, {
|
|
10
|
-
...desc,
|
|
11
|
-
get() {
|
|
12
|
-
return this[sourceKey][key];
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
else if (typeof desc.value === "function") Object.defineProperty(target, key, {
|
|
16
|
-
...desc,
|
|
17
|
-
value(...args) {
|
|
18
|
-
return this[sourceKey][key](...args);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
else Object.defineProperty(target, key, desc);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
6
|
|
|
25
7
|
//#endregion
|
|
26
8
|
//#region src/adapters/_node/headers.ts
|
|
@@ -283,11 +265,11 @@ const NodeResponse = /* @__PURE__ */ (() => {
|
|
|
283
265
|
};
|
|
284
266
|
}
|
|
285
267
|
}
|
|
286
|
-
|
|
268
|
+
lazyInherit(NodeResponse$1.prototype, NativeResponse.prototype, "_response");
|
|
287
269
|
Object.setPrototypeOf(NodeResponse$1, NativeResponse);
|
|
288
270
|
Object.setPrototypeOf(NodeResponse$1.prototype, NativeResponse.prototype);
|
|
289
271
|
return NodeResponse$1;
|
|
290
272
|
})();
|
|
291
273
|
|
|
292
274
|
//#endregion
|
|
293
|
-
export { NodeRequestHeaders, NodeResponse, NodeResponseHeaders
|
|
275
|
+
export { NodeRequestHeaders, NodeResponse, NodeResponseHeaders };
|
package/dist/adapters/bun.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-hx5EhU1U.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-BQeTFJZ1.mjs";
|
|
3
3
|
import * as bun from "bun";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/bun.d.ts
|
package/dist/adapters/bun.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DRF_4b_y.mjs";
|
|
2
2
|
import { wrapFetch } from "../_chunks/_middleware-BvRR7B4M.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "../_chunks/_inherit-DLZfB57K.mjs";
|
|
4
|
+
import { FastURL$1 as FastURL } from "../_chunks/_url-Q_-LB8LX.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/adapters/bun.ts
|
|
6
7
|
const FastResponse = Response;
|
package/dist/adapters/deno.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-hx5EhU1U.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-BQeTFJZ1.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/deno.d.ts
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
package/dist/adapters/deno.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DRF_4b_y.mjs";
|
|
2
2
|
import { wrapFetch } from "../_chunks/_middleware-BvRR7B4M.mjs";
|
|
3
|
-
import
|
|
3
|
+
import "../_chunks/_inherit-DLZfB57K.mjs";
|
|
4
|
+
import { FastURL$1 as FastURL } from "../_chunks/_url-Q_-LB8LX.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/adapters/deno.ts
|
|
6
7
|
const FastResponse = Response;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createWaitUntil } from "../_chunks/_utils-DRF_4b_y.mjs";
|
|
2
2
|
import { wrapFetch } from "../_chunks/_middleware-BvRR7B4M.mjs";
|
|
3
|
-
import { errorPlugin } from "../_chunks/_plugins-
|
|
3
|
+
import { errorPlugin } from "../_chunks/_plugins-DmMfurBQ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/generic.ts
|
|
6
6
|
const FastURL = URL;
|
package/dist/adapters/node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-
|
|
2
|
-
import { FastURL$2 as FastURL } from "../_chunks/_url-
|
|
1
|
+
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-hx5EhU1U.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-BQeTFJZ1.mjs";
|
|
3
3
|
import NodeHttp from "node:http";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
|
|
@@ -11,7 +11,6 @@ type NodeRequestContext = {
|
|
|
11
11
|
declare const NodeRequest: {
|
|
12
12
|
new (nodeCtx: NodeRequestContext): ServerRequest;
|
|
13
13
|
};
|
|
14
|
-
type NodeRequest = InstanceType<typeof NodeRequest>;
|
|
15
14
|
//#endregion
|
|
16
15
|
//#region src/adapters/_node/headers.d.ts
|
|
17
16
|
type NodeRequestHeaders = InstanceType<typeof NodeRequestHeaders>;
|
package/dist/adapters/node.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createWaitUntil, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_utils-DRF_4b_y.mjs";
|
|
2
2
|
import { wrapFetch } from "../_chunks/_middleware-BvRR7B4M.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { lazyInherit } from "../_chunks/_inherit-DLZfB57K.mjs";
|
|
4
|
+
import { FastURL$1 as FastURL } from "../_chunks/_url-Q_-LB8LX.mjs";
|
|
5
|
+
import { NodeRequestHeaders, NodeResponse, NodeResponseHeaders } from "../_chunks/response-iYyldB4J.mjs";
|
|
6
|
+
import { errorPlugin } from "../_chunks/_plugins-DmMfurBQ.mjs";
|
|
6
7
|
import { splitSetCookieString } from "cookie-es";
|
|
7
8
|
|
|
8
9
|
//#region src/adapters/_node/send.ts
|
|
@@ -67,175 +68,36 @@ function streamBody(stream, nodeRes) {
|
|
|
67
68
|
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region src/adapters/_node/url.ts
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
get hash() {
|
|
86
|
-
return this._hash;
|
|
87
|
-
}
|
|
88
|
-
set hash(value) {
|
|
89
|
-
this._hash = value;
|
|
90
|
-
}
|
|
91
|
-
get username() {
|
|
92
|
-
return this._username;
|
|
93
|
-
}
|
|
94
|
-
set username(value) {
|
|
95
|
-
this._username = value;
|
|
96
|
-
}
|
|
97
|
-
get password() {
|
|
98
|
-
return this._password;
|
|
99
|
-
}
|
|
100
|
-
set password(value) {
|
|
101
|
-
this._password = value;
|
|
102
|
-
}
|
|
103
|
-
get host() {
|
|
104
|
-
return this._node.req.headers.host || this._node.req.headers[":authority"] || "";
|
|
105
|
-
}
|
|
106
|
-
set host(value) {
|
|
107
|
-
this._hostname = void 0;
|
|
108
|
-
this._port = void 0;
|
|
109
|
-
this._node.req.headers.host = value;
|
|
110
|
-
}
|
|
111
|
-
get hostname() {
|
|
112
|
-
if (this._hostname === void 0) {
|
|
113
|
-
const [hostname, port] = parseHost(this._node.req.headers.host);
|
|
114
|
-
if (this._port === void 0 && port) this._port = String(Number.parseInt(port) || "");
|
|
115
|
-
this._hostname = hostname || "localhost";
|
|
116
|
-
}
|
|
117
|
-
return this._hostname;
|
|
118
|
-
}
|
|
119
|
-
set hostname(value) {
|
|
120
|
-
this._hostname = value;
|
|
121
|
-
}
|
|
122
|
-
get port() {
|
|
123
|
-
if (this._port === void 0) {
|
|
124
|
-
const [hostname, port] = parseHost(this._node.req.headers.host);
|
|
125
|
-
if (this._hostname === void 0 && hostname) this._hostname = hostname;
|
|
126
|
-
this._port = port || String(this._node.req.socket?.localPort || "");
|
|
127
|
-
}
|
|
128
|
-
return this._port;
|
|
129
|
-
}
|
|
130
|
-
set port(value) {
|
|
131
|
-
this._port = String(Number.parseInt(value) || "");
|
|
132
|
-
}
|
|
133
|
-
get pathname() {
|
|
134
|
-
if (this._pathname === void 0) {
|
|
135
|
-
const [pathname, search] = parsePath(this._node.req.url || "/");
|
|
136
|
-
this._pathname = pathname;
|
|
137
|
-
if (this._search === void 0) this._search = search;
|
|
138
|
-
}
|
|
139
|
-
return this._pathname;
|
|
140
|
-
}
|
|
141
|
-
set pathname(value) {
|
|
142
|
-
if (value[0] !== "/") value = "/" + value;
|
|
143
|
-
if (value === this._pathname) return;
|
|
144
|
-
this._pathname = value;
|
|
145
|
-
this._node.req.url = value + this.search;
|
|
146
|
-
}
|
|
147
|
-
get search() {
|
|
148
|
-
if (this._search === void 0) {
|
|
149
|
-
const [pathname, search] = parsePath(this._node.req.url || "/");
|
|
150
|
-
this._search = search;
|
|
151
|
-
if (this._pathname === void 0) this._pathname = pathname;
|
|
152
|
-
}
|
|
153
|
-
return this._search;
|
|
154
|
-
}
|
|
155
|
-
set search(value) {
|
|
156
|
-
if (value === "?") value = "";
|
|
157
|
-
else if (value && value[0] !== "?") value = "?" + value;
|
|
158
|
-
if (value === this._search) return;
|
|
159
|
-
this._search = value;
|
|
160
|
-
this._searchParams = void 0;
|
|
161
|
-
this._node.req.url = this.pathname + value;
|
|
162
|
-
}
|
|
163
|
-
get searchParams() {
|
|
164
|
-
if (!this._searchParams) this._searchParams = new URLSearchParams(this.search);
|
|
165
|
-
return this._searchParams;
|
|
166
|
-
}
|
|
167
|
-
set searchParams(value) {
|
|
168
|
-
this._searchParams = value;
|
|
169
|
-
this._search = value.toString();
|
|
170
|
-
}
|
|
171
|
-
get protocol() {
|
|
172
|
-
if (!this._protocol) this._protocol = this._node.req.socket?.encrypted || this._node.req.headers["x-forwarded-proto"] === "https" ? "https:" : "http:";
|
|
173
|
-
return this._protocol;
|
|
174
|
-
}
|
|
175
|
-
set protocol(value) {
|
|
176
|
-
this._protocol = value;
|
|
177
|
-
}
|
|
178
|
-
get origin() {
|
|
179
|
-
return `${this.protocol}//${this.host}`;
|
|
180
|
-
}
|
|
181
|
-
set origin(_value) {}
|
|
182
|
-
get href() {
|
|
183
|
-
return `${this.protocol}//${this.host}${this.pathname}${this.search}`;
|
|
184
|
-
}
|
|
185
|
-
set href(value) {
|
|
186
|
-
const _url = new globalThis.URL(value);
|
|
187
|
-
this._protocol = _url.protocol;
|
|
188
|
-
this.username = _url.username;
|
|
189
|
-
this.password = _url.password;
|
|
190
|
-
this._hostname = _url.hostname;
|
|
191
|
-
this._port = _url.port;
|
|
192
|
-
this.pathname = _url.pathname;
|
|
193
|
-
this.search = _url.search;
|
|
194
|
-
this.hash = _url.hash;
|
|
195
|
-
}
|
|
196
|
-
toString() {
|
|
197
|
-
return this.href;
|
|
198
|
-
}
|
|
199
|
-
toJSON() {
|
|
200
|
-
return this.href;
|
|
201
|
-
}
|
|
202
|
-
get [Symbol.toStringTag]() {
|
|
203
|
-
return "URL";
|
|
204
|
-
}
|
|
205
|
-
[kNodeInspect]() {
|
|
206
|
-
return this.href;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
Object.setPrototypeOf(_URL.prototype, globalThis.URL.prototype);
|
|
210
|
-
return _URL;
|
|
211
|
-
})();
|
|
212
|
-
function parsePath(input) {
|
|
213
|
-
const url = (input || "/").replace(/\\/g, "/");
|
|
214
|
-
const qIndex = url.indexOf("?");
|
|
215
|
-
if (qIndex === -1) return [url, ""];
|
|
216
|
-
return [url.slice(0, qIndex), url.slice(qIndex)];
|
|
217
|
-
}
|
|
218
|
-
function parseHost(host) {
|
|
219
|
-
const s = (host || "").split(":");
|
|
220
|
-
return [s[0], String(Number.parseInt(s[1]) || "")];
|
|
221
|
-
}
|
|
71
|
+
var NodeRequestURL = class extends FastURL {
|
|
72
|
+
constructor({ req }) {
|
|
73
|
+
const host = req.headers.host || req.headers[":authority"] || `${req.socket.localFamily === "IPv6" ? "[" + req.socket.localAddress + "]" : req.socket.localAddress}:${req.socket?.localPort || "80"}`;
|
|
74
|
+
const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" ? "https:" : "http:";
|
|
75
|
+
const qIndex = (req.url || "/").indexOf("?");
|
|
76
|
+
const pathname = qIndex === -1 ? req.url || "/" : req.url?.slice(0, qIndex) || "/";
|
|
77
|
+
const search = qIndex === -1 ? "" : req.url?.slice(qIndex) || "";
|
|
78
|
+
super({
|
|
79
|
+
protocol,
|
|
80
|
+
host,
|
|
81
|
+
pathname,
|
|
82
|
+
search
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
222
86
|
|
|
223
87
|
//#endregion
|
|
224
88
|
//#region src/adapters/_node/request.ts
|
|
225
89
|
const NodeRequest = /* @__PURE__ */ (() => {
|
|
226
|
-
const NativeRequest = globalThis.Request;
|
|
227
90
|
const { Readable } = process.getBuiltinModule("node:stream");
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
91
|
+
const NativeRequest = globalThis._Request ??= globalThis.Request;
|
|
92
|
+
const PatchedRequest = class Request extends NativeRequest {
|
|
93
|
+
static _srvx = true;
|
|
94
|
+
constructor(input, options) {
|
|
95
|
+
if (typeof input === "object" && "_request" in input) input = input._request;
|
|
96
|
+
if ((options?.body)?.getReader !== void 0) options.duplex ??= "half";
|
|
97
|
+
super(input, options);
|
|
236
98
|
}
|
|
237
|
-
|
|
238
|
-
|
|
99
|
+
};
|
|
100
|
+
if (!globalThis.Request._srvx) globalThis.Request = PatchedRequest;
|
|
239
101
|
class NodeRequest$1 {
|
|
240
102
|
_node;
|
|
241
103
|
_url;
|
|
@@ -276,7 +138,7 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
276
138
|
if (!this.#request) {
|
|
277
139
|
const method = this.method;
|
|
278
140
|
const hasBody = !(method === "GET" || method === "HEAD");
|
|
279
|
-
this.#request = new
|
|
141
|
+
this.#request = new PatchedRequest(this.url, {
|
|
280
142
|
method,
|
|
281
143
|
headers: this.headers,
|
|
282
144
|
signal: this.signal,
|
|
@@ -286,8 +148,8 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
286
148
|
return this.#request;
|
|
287
149
|
}
|
|
288
150
|
}
|
|
289
|
-
|
|
290
|
-
Object.setPrototypeOf(NodeRequest$1.prototype,
|
|
151
|
+
lazyInherit(NodeRequest$1.prototype, NativeRequest.prototype, "_request");
|
|
152
|
+
Object.setPrototypeOf(NodeRequest$1.prototype, PatchedRequest.prototype);
|
|
291
153
|
return NodeRequest$1;
|
|
292
154
|
})();
|
|
293
155
|
|
package/dist/cli.mjs
CHANGED
|
@@ -61,6 +61,20 @@ async function main(mainOpts) {
|
|
|
61
61
|
process.exit(code);
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
+
let cleanupCalled = false;
|
|
65
|
+
const cleanup = (signal, exitCode) => {
|
|
66
|
+
if (cleanupCalled) return;
|
|
67
|
+
cleanupCalled = true;
|
|
68
|
+
try {
|
|
69
|
+
child.kill(signal || "SIGTERM");
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("Error killing child process:", error);
|
|
72
|
+
}
|
|
73
|
+
if (exitCode !== void 0) process.exit(exitCode);
|
|
74
|
+
};
|
|
75
|
+
process.on("exit", () => cleanup("SIGTERM"));
|
|
76
|
+
process.on("SIGINT", () => cleanup("SIGINT", 130));
|
|
77
|
+
process.on("SIGTERM", () => cleanup("SIGTERM", 143));
|
|
64
78
|
}
|
|
65
79
|
async function serve() {
|
|
66
80
|
try {
|
|
@@ -88,15 +102,18 @@ async function serve() {
|
|
|
88
102
|
await server.ready();
|
|
89
103
|
await globalThis.__srvx_listen_cb__?.();
|
|
90
104
|
printInfo(entry);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
let cleanupCalled = false;
|
|
106
|
+
const cleanup = (exitCode) => {
|
|
107
|
+
if (cleanupCalled) return;
|
|
108
|
+
cleanupCalled = true;
|
|
109
|
+
console.log(Colors.gray("\rGracefully stopping server..."));
|
|
110
|
+
server.close(true).catch(console.error).then(() => {
|
|
111
|
+
console.log(Colors.gray("Server stopped."));
|
|
112
|
+
process.exit(exitCode || 0);
|
|
113
|
+
});
|
|
94
114
|
};
|
|
95
|
-
process.on("SIGINT", () =>
|
|
96
|
-
|
|
97
|
-
cleanup();
|
|
98
|
-
});
|
|
99
|
-
process.on("SIGTERM", cleanup);
|
|
115
|
+
process.on("SIGINT", () => cleanup(130));
|
|
116
|
+
process.on("SIGTERM", () => cleanup(143));
|
|
100
117
|
} catch (error) {
|
|
101
118
|
console.error(error);
|
|
102
119
|
process.exit(1);
|
|
@@ -130,7 +147,7 @@ async function loadEntry(opts) {
|
|
|
130
147
|
const nodeHandler = listenHandler || (typeof mod.default === "function" ? mod.default : void 0);
|
|
131
148
|
if (nodeHandler) {
|
|
132
149
|
_legacyNode = true;
|
|
133
|
-
const { callNodeHandler } = await import("./_chunks/call-
|
|
150
|
+
const { callNodeHandler } = await import("./_chunks/call-DYf04jcm.mjs");
|
|
134
151
|
fetchHandler = (webReq) => callNodeHandler(nodeHandler, webReq);
|
|
135
152
|
}
|
|
136
153
|
}
|
|
@@ -216,7 +233,7 @@ async function interceptListen(cb) {
|
|
|
216
233
|
};
|
|
217
234
|
}
|
|
218
235
|
async function version() {
|
|
219
|
-
const version$1 = "0.8.
|
|
236
|
+
const version$1 = "0.8.10";
|
|
220
237
|
return `srvx ${version$1}\n${runtime()}`;
|
|
221
238
|
}
|
|
222
239
|
function runtime() {
|
package/dist/log.d.mts
CHANGED
package/dist/static.d.mts
CHANGED
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve } from "./_chunks/types-
|
|
1
|
+
import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve } from "./_chunks/types-hx5EhU1U.mjs";
|
|
2
2
|
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.10",
|
|
4
4
|
"description": "Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.",
|
|
5
5
|
"homepage": "https://srvx.h3.dev",
|
|
6
6
|
"repository": "h3js/srvx",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"bench:node": "node test/bench-node/_run.mjs",
|
|
40
40
|
"bench:url:bun": "bun run ./test/url.bench.ts",
|
|
41
41
|
"bench:url:deno": "deno run -A ./test/url.bench.ts",
|
|
42
|
-
"bench:url:node": "pnpm --expose-gc --allow-natives-syntax ./test/url.bench.ts",
|
|
42
|
+
"bench:url:node": "pnpm --expose-gc --allow-natives-syntax node ./test/url.bench.ts",
|
|
43
43
|
"build": "obuild",
|
|
44
44
|
"dev": "vitest dev",
|
|
45
45
|
"lint": "eslint . && prettier -c .",
|
|
@@ -58,20 +58,20 @@
|
|
|
58
58
|
"cookie-es": "^2.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@cloudflare/workers-types": "^4.
|
|
61
|
+
"@cloudflare/workers-types": "^4.20251004.0",
|
|
62
62
|
"@hono/node-server": "^1.19.5",
|
|
63
63
|
"@mitata/counters": "^0.0.8",
|
|
64
64
|
"@mjackson/node-fetch-server": "^0.7.0",
|
|
65
65
|
"@types/bun": "^1.2.23",
|
|
66
|
-
"@types/deno": "^2.
|
|
67
|
-
"@types/node": "^24.
|
|
66
|
+
"@types/deno": "^2.5.0",
|
|
67
|
+
"@types/node": "^24.6.2",
|
|
68
68
|
"@types/node-forge": "^1.3.14",
|
|
69
|
-
"@types/serviceworker": "^0.0.
|
|
69
|
+
"@types/serviceworker": "^0.0.157",
|
|
70
70
|
"@vitest/coverage-v8": "^3.2.4",
|
|
71
71
|
"@whatwg-node/server": "^0.10.12",
|
|
72
72
|
"automd": "^0.4.2",
|
|
73
73
|
"changelogen": "^0.6.2",
|
|
74
|
-
"eslint": "^9.
|
|
74
|
+
"eslint": "^9.37.0",
|
|
75
75
|
"eslint-config-unjs": "^0.5.0",
|
|
76
76
|
"execa": "^9.6.0",
|
|
77
77
|
"get-port-please": "^3.2.0",
|
|
@@ -80,13 +80,13 @@
|
|
|
80
80
|
"node-forge": "^1.3.1",
|
|
81
81
|
"obuild": "^0.2.1",
|
|
82
82
|
"prettier": "^3.6.2",
|
|
83
|
-
"srvx-release": "npm:srvx@0.8.
|
|
83
|
+
"srvx-release": "npm:srvx@0.8.9",
|
|
84
84
|
"tslib": "^2.8.1",
|
|
85
|
-
"typescript": "^5.9.
|
|
85
|
+
"typescript": "^5.9.3",
|
|
86
86
|
"undici": "^7.16.0",
|
|
87
87
|
"vitest": "^3.2.4"
|
|
88
88
|
},
|
|
89
|
-
"packageManager": "pnpm@10.
|
|
89
|
+
"packageManager": "pnpm@10.18.0",
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=20.16.0"
|
|
92
92
|
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
//#region src/_url.ts
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper for URL with fast path access to `.pathname` and `.search` props.
|
|
4
|
-
*
|
|
5
|
-
* **NOTE:** It is assumed that the input URL is already ecoded and formatted from an HTTP request and contains no hash.
|
|
6
|
-
*
|
|
7
|
-
* **NOTE:** Triggering the setters or getters on other props will deoptimize to full URL parsing.
|
|
8
|
-
*/
|
|
9
|
-
const FastURL = /* @__PURE__ */ (() => {
|
|
10
|
-
const FastURL$1 = class URL {
|
|
11
|
-
#originalURL;
|
|
12
|
-
#parsedURL;
|
|
13
|
-
_pathname;
|
|
14
|
-
_urlqindex;
|
|
15
|
-
_query;
|
|
16
|
-
_search;
|
|
17
|
-
constructor(url) {
|
|
18
|
-
this.#originalURL = url;
|
|
19
|
-
}
|
|
20
|
-
get _url() {
|
|
21
|
-
if (!this.#parsedURL) this.#parsedURL = new globalThis.URL(this.#originalURL);
|
|
22
|
-
return this.#parsedURL;
|
|
23
|
-
}
|
|
24
|
-
toString() {
|
|
25
|
-
return this._url.toString();
|
|
26
|
-
}
|
|
27
|
-
toJSON() {
|
|
28
|
-
return this.toString();
|
|
29
|
-
}
|
|
30
|
-
get pathname() {
|
|
31
|
-
if (this.#parsedURL) return this.#parsedURL.pathname;
|
|
32
|
-
if (this._pathname === void 0) {
|
|
33
|
-
const url = this.#originalURL;
|
|
34
|
-
const protoIndex = url.indexOf("://");
|
|
35
|
-
if (protoIndex === -1) return this._url.pathname;
|
|
36
|
-
const pIndex = url.indexOf("/", protoIndex + 4);
|
|
37
|
-
if (pIndex === -1) return this._url.pathname;
|
|
38
|
-
const qIndex = this._urlqindex = url.indexOf("?", pIndex);
|
|
39
|
-
this._pathname = url.slice(pIndex, qIndex === -1 ? void 0 : qIndex);
|
|
40
|
-
}
|
|
41
|
-
return this._pathname;
|
|
42
|
-
}
|
|
43
|
-
set pathname(value) {
|
|
44
|
-
this._pathname = void 0;
|
|
45
|
-
this._url.pathname = value;
|
|
46
|
-
}
|
|
47
|
-
get searchParams() {
|
|
48
|
-
if (this.#parsedURL) return this.#parsedURL.searchParams;
|
|
49
|
-
if (!this._query) this._query = new URLSearchParams(this.search);
|
|
50
|
-
return this._query;
|
|
51
|
-
}
|
|
52
|
-
get search() {
|
|
53
|
-
if (this.#parsedURL) return this.#parsedURL.search;
|
|
54
|
-
if (this._search === void 0) {
|
|
55
|
-
const qIndex = this._urlqindex;
|
|
56
|
-
if (qIndex === -1 || qIndex === this.#originalURL.length - 1) this._search = "";
|
|
57
|
-
else this._search = qIndex === void 0 ? this._url.search : this.#originalURL.slice(qIndex);
|
|
58
|
-
}
|
|
59
|
-
return this._search;
|
|
60
|
-
}
|
|
61
|
-
set search(value) {
|
|
62
|
-
this._search = void 0;
|
|
63
|
-
this._query = void 0;
|
|
64
|
-
this._url.search = value;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const slowProps = [
|
|
68
|
-
"hash",
|
|
69
|
-
"host",
|
|
70
|
-
"hostname",
|
|
71
|
-
"href",
|
|
72
|
-
"origin",
|
|
73
|
-
"password",
|
|
74
|
-
"port",
|
|
75
|
-
"protocol",
|
|
76
|
-
"username"
|
|
77
|
-
];
|
|
78
|
-
for (const prop of slowProps) Object.defineProperty(FastURL$1.prototype, prop, {
|
|
79
|
-
get() {
|
|
80
|
-
return this._url[prop];
|
|
81
|
-
},
|
|
82
|
-
set(value) {
|
|
83
|
-
this._url[prop] = value;
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
Object.setPrototypeOf(FastURL$1, globalThis.URL);
|
|
87
|
-
return FastURL$1;
|
|
88
|
-
})();
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
export { FastURL as FastURL$1 };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/_url.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper for URL with fast path access to `.pathname` and `.search` props.
|
|
4
|
-
*
|
|
5
|
-
* **NOTE:** It is assumed that the input URL is already ecoded and formatted from an HTTP request and contains no hash.
|
|
6
|
-
*
|
|
7
|
-
* **NOTE:** Triggering the setters or getters on other props will deoptimize to full URL parsing.
|
|
8
|
-
*/
|
|
9
|
-
declare const FastURL: {
|
|
10
|
-
new (url: string): URL;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { FastURL as FastURL$2 };
|
|
File without changes
|
|
File without changes
|