srvx 0.7.0 → 0.7.2
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/{_url.d.mts → _chunks/_url-0kFTYgtJ.d.mts} +1 -1
- package/dist/{_url.mjs → _chunks/_url-Dsik4Hgl.mjs} +2 -6
- package/dist/_chunks/types-CAoaOHnD.d.mts +247 -0
- package/dist/{bun.d.mts → adapters/bun.d.mts} +3 -3
- package/dist/{bun.mjs → adapters/bun.mjs} +3 -3
- package/dist/{cloudflare.d.mts → adapters/cloudflare.d.mts} +1 -2
- package/dist/{cloudflare.mjs → adapters/cloudflare.mjs} +3 -3
- package/dist/{deno.d.mts → adapters/deno.d.mts} +3 -3
- package/dist/{deno.mjs → adapters/deno.mjs} +3 -3
- package/dist/{generic.d.mts → adapters/generic.d.mts} +1 -2
- package/dist/{generic.mjs → adapters/generic.mjs} +2 -2
- package/dist/{node.d.mts → adapters/node.d.mts} +2 -6
- package/dist/{node.mjs → adapters/node.mjs} +9 -4
- package/dist/{service-worker.d.mts → adapters/service-worker.d.mts} +1 -2
- package/dist/{service-worker.mjs → adapters/service-worker.mjs} +3 -3
- package/dist/types.d.mts +2 -228
- package/package.json +27 -25
- /package/dist/{_middleware.mjs → _chunks/_middleware-Bz7WmB2e.mjs} +0 -0
- /package/dist/{_plugins.mjs → _chunks/_plugins-CDyQtZq-.mjs} +0 -0
|
@@ -89,11 +89,7 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
89
89
|
const url = this.#originalURL;
|
|
90
90
|
const protoIndex = url.indexOf("://");
|
|
91
91
|
if (protoIndex === -1) return this._url.pathname;
|
|
92
|
-
const pIndex = url.indexOf(
|
|
93
|
-
"/",
|
|
94
|
-
protoIndex + 4
|
|
95
|
-
/* :// */
|
|
96
|
-
);
|
|
92
|
+
const pIndex = url.indexOf("/", protoIndex + 4);
|
|
97
93
|
if (pIndex === -1) return this._url.pathname;
|
|
98
94
|
const qIndex = this._urlqindex = url.indexOf("?", pIndex);
|
|
99
95
|
this._pathname = url.slice(pIndex, qIndex === -1 ? void 0 : qIndex);
|
|
@@ -148,4 +144,4 @@ const FastURL = /* @__PURE__ */ (() => {
|
|
|
148
144
|
})();
|
|
149
145
|
|
|
150
146
|
//#endregion
|
|
151
|
-
export { FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions };
|
|
147
|
+
export { FastURL as FastURL$1, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import * as NodeHttp$1 from "node:http";
|
|
2
|
+
import * as NodeHttps from "node:https";
|
|
3
|
+
import * as NodeHttp2 from "node:http2";
|
|
4
|
+
import * as NodeNet from "node:net";
|
|
5
|
+
import * as Bun from "bun";
|
|
6
|
+
import * as CF from "@cloudflare/workers-types";
|
|
7
|
+
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
11
|
+
// srvx API
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Faster URL constructor with lazy access to pathname and search params (For Node, Deno, and Bun).
|
|
15
|
+
*/
|
|
16
|
+
declare const FastURL: typeof globalThis.URL;
|
|
17
|
+
/**
|
|
18
|
+
* Faster Response constructor optimized for Node.js (same as Response for other runtimes).
|
|
19
|
+
*/
|
|
20
|
+
declare const FastResponse: typeof globalThis.Response;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new server instance.
|
|
23
|
+
*/
|
|
24
|
+
declare function serve(options: ServerOptions): Server;
|
|
25
|
+
/**
|
|
26
|
+
* Web fetch compatible request handler
|
|
27
|
+
*/
|
|
28
|
+
type ServerHandler = (request: ServerRequest) => MaybePromise<Response>;
|
|
29
|
+
type ServerMiddleware = (request: ServerRequest, next: () => Response | Promise<Response>) => Response | Promise<Response>;
|
|
30
|
+
type ServerPlugin = (server: Server) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Server options
|
|
33
|
+
*/
|
|
34
|
+
interface ServerOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The fetch handler handles incoming requests.
|
|
37
|
+
*/
|
|
38
|
+
fetch: ServerHandler;
|
|
39
|
+
/**
|
|
40
|
+
* Handle lifecycle errors.
|
|
41
|
+
*
|
|
42
|
+
* @note This handler will set built-in Bun and Deno error handler.
|
|
43
|
+
*/
|
|
44
|
+
error?: ErrorHandler;
|
|
45
|
+
/**
|
|
46
|
+
* Server middleware handlers to run before the main fetch handler.
|
|
47
|
+
*/
|
|
48
|
+
middleware?: ServerMiddleware[];
|
|
49
|
+
/**
|
|
50
|
+
* Server plugins.
|
|
51
|
+
*/
|
|
52
|
+
plugins?: ServerPlugin[];
|
|
53
|
+
/**
|
|
54
|
+
* If set to `true`, server will not start listening automatically.
|
|
55
|
+
*/
|
|
56
|
+
manual?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The port server should be listening to.
|
|
59
|
+
*
|
|
60
|
+
* Default is read from `PORT` environment variable or will be `3000`.
|
|
61
|
+
*
|
|
62
|
+
* **Tip:** You can set the port to `0` to use a random port.
|
|
63
|
+
*/
|
|
64
|
+
port?: string | number;
|
|
65
|
+
/**
|
|
66
|
+
* The hostname (IP or resolvable host) server listener should bound to.
|
|
67
|
+
*
|
|
68
|
+
* When not provided, server with listen to all network interfaces by default.
|
|
69
|
+
*
|
|
70
|
+
* **Important:** If you are running a server that is not expected to be exposed to the network, use `hostname: "localhost"`.
|
|
71
|
+
*/
|
|
72
|
+
hostname?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Enabling this option allows multiple processes to bind to the same port, which is useful for load balancing.
|
|
75
|
+
*
|
|
76
|
+
* **Note:** Despite Node.js built-in behavior that has `exclusive` flag (opposite of `reusePort`) enabled by default, srvx uses non-exclusive mode for consistency.
|
|
77
|
+
*/
|
|
78
|
+
reusePort?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The protocol to use for the server.
|
|
81
|
+
*
|
|
82
|
+
* Possible values are `http` and `https`.
|
|
83
|
+
*
|
|
84
|
+
* If `protocol` is not set, Server will use `http` as the default protocol or `https` if both `tls.cert` and `tls.key` options are provided.
|
|
85
|
+
*/
|
|
86
|
+
protocol?: "http" | "https";
|
|
87
|
+
/**
|
|
88
|
+
* If set to `true`, server will not print the listening address.
|
|
89
|
+
*/
|
|
90
|
+
silent?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* TLS server options.
|
|
93
|
+
*/
|
|
94
|
+
tls?: {
|
|
95
|
+
/**
|
|
96
|
+
* File path or inlined TLS certificate in PEM format (required).
|
|
97
|
+
*/
|
|
98
|
+
cert?: string;
|
|
99
|
+
/**
|
|
100
|
+
* File path or inlined TLS private key in PEM format (required).
|
|
101
|
+
*/
|
|
102
|
+
key?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Passphrase for the private key (optional).
|
|
105
|
+
*/
|
|
106
|
+
passphrase?: string;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Node.js server options.
|
|
110
|
+
*/
|
|
111
|
+
node?: (NodeHttp$1.ServerOptions | NodeHttps.ServerOptions | NodeHttp2.ServerOptions) & NodeNet.ListenOptions & {
|
|
112
|
+
http2?: boolean;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Bun server options
|
|
116
|
+
*
|
|
117
|
+
* @docs https://bun.sh/docs/api/http
|
|
118
|
+
*/
|
|
119
|
+
bun?: Omit<Bun.ServeOptions | Bun.TLSServeOptions, "fetch">;
|
|
120
|
+
/**
|
|
121
|
+
* Deno server options
|
|
122
|
+
*
|
|
123
|
+
* @docs https://docs.deno.com/api/deno/~/Deno.serve
|
|
124
|
+
*/
|
|
125
|
+
deno?: Deno.ServeOptions;
|
|
126
|
+
/**
|
|
127
|
+
* Service worker options
|
|
128
|
+
*/
|
|
129
|
+
serviceWorker?: {
|
|
130
|
+
/**
|
|
131
|
+
* The path to the service worker file to be registered.
|
|
132
|
+
*/
|
|
133
|
+
url?: string;
|
|
134
|
+
/**
|
|
135
|
+
* The scope of the service worker.
|
|
136
|
+
*
|
|
137
|
+
*/
|
|
138
|
+
scope?: string;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
interface Server<Handler = ServerHandler> {
|
|
142
|
+
/**
|
|
143
|
+
* Current runtime name
|
|
144
|
+
*/
|
|
145
|
+
readonly runtime: "node" | "deno" | "bun" | "cloudflare" | "service-worker" | "generic";
|
|
146
|
+
/**
|
|
147
|
+
* Server options
|
|
148
|
+
*/
|
|
149
|
+
readonly options: ServerOptions & {
|
|
150
|
+
middleware: ServerMiddleware[];
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Server URL address.
|
|
154
|
+
*/
|
|
155
|
+
readonly url?: string;
|
|
156
|
+
/**
|
|
157
|
+
* Node.js context.
|
|
158
|
+
*/
|
|
159
|
+
readonly node?: {
|
|
160
|
+
server?: NodeHttp$1.Server | NodeHttp2.Http2Server;
|
|
161
|
+
handler: (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Bun context.
|
|
165
|
+
*/
|
|
166
|
+
readonly bun?: {
|
|
167
|
+
server?: Bun.Server;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Deno context.
|
|
171
|
+
*/
|
|
172
|
+
readonly deno?: {
|
|
173
|
+
server?: Deno.HttpServer;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Server fetch handler
|
|
177
|
+
*/
|
|
178
|
+
readonly fetch: Handler;
|
|
179
|
+
/**
|
|
180
|
+
* Returns a promise that resolves when the server is ready.
|
|
181
|
+
*/
|
|
182
|
+
ready(): Promise<Server<Handler>>;
|
|
183
|
+
/**
|
|
184
|
+
* Stop listening to prevent new connections from being accepted.
|
|
185
|
+
*
|
|
186
|
+
* By default, it does not cancel in-flight requests or websockets. That means it may take some time before all network activity stops.
|
|
187
|
+
*
|
|
188
|
+
* @param closeActiveConnections Immediately terminate in-flight requests, websockets, and stop accepting new connections.
|
|
189
|
+
* @default false
|
|
190
|
+
*/
|
|
191
|
+
close(closeActiveConnections?: boolean): Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
// ----------------------------------------------------------------------------
|
|
194
|
+
// Request with runtime addons.
|
|
195
|
+
// ----------------------------------------------------------------------------
|
|
196
|
+
interface ServerRuntimeContext {
|
|
197
|
+
name: "node" | "deno" | "bun" | "cloudflare" | (string & {});
|
|
198
|
+
/**
|
|
199
|
+
* Underlying Node.js server request info.
|
|
200
|
+
*/
|
|
201
|
+
node?: {
|
|
202
|
+
req: NodeServerRequest;
|
|
203
|
+
res?: NodeServerResponse;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Underlying Deno server request info.
|
|
207
|
+
*/
|
|
208
|
+
deno?: {
|
|
209
|
+
info: Deno.ServeHandlerInfo<Deno.NetAddr>;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Underlying Bun server request context.
|
|
213
|
+
*/
|
|
214
|
+
bun?: {
|
|
215
|
+
server: Bun.Server;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Underlying Cloudflare request context.
|
|
219
|
+
*/
|
|
220
|
+
cloudflare?: {
|
|
221
|
+
env: unknown;
|
|
222
|
+
context: CF.ExecutionContext;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
interface ServerRequest extends Request {
|
|
226
|
+
/**
|
|
227
|
+
* Runtime specific request context.
|
|
228
|
+
*/
|
|
229
|
+
runtime?: ServerRuntimeContext;
|
|
230
|
+
/**
|
|
231
|
+
* IP address of the client.
|
|
232
|
+
*/
|
|
233
|
+
ip?: string | undefined;
|
|
234
|
+
}
|
|
235
|
+
// ----------------------------------------------------------------------------
|
|
236
|
+
// Different handler types
|
|
237
|
+
// ----------------------------------------------------------------------------
|
|
238
|
+
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
239
|
+
type ErrorHandler = (error: unknown) => Response | Promise<Response>;
|
|
240
|
+
type BunFetchHandler = (request: Request, server?: Bun.Server) => Response | Promise<Response>;
|
|
241
|
+
type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
|
|
242
|
+
type NodeServerRequest = NodeHttp$1.IncomingMessage | NodeHttp2.Http2ServerRequest;
|
|
243
|
+
type NodeServerResponse = NodeHttp$1.ServerResponse | NodeHttp2.Http2ServerResponse;
|
|
244
|
+
type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
245
|
+
type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
|
|
246
|
+
//#endregion
|
|
247
|
+
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BunFetchHandler, Server, ServerOptions } from "
|
|
2
|
-
import { FastURL$
|
|
1
|
+
import { BunFetchHandler, Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.mjs";
|
|
3
3
|
import * as bun from "bun";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/bun.d.ts
|
|
6
6
|
declare const FastResponse: typeof globalThis.Response;
|
|
7
7
|
declare function serve(options: ServerOptions): BunServer;
|
|
8
|
+
// https://bun.sh/docs/api/http
|
|
8
9
|
declare class BunServer implements Server<BunFetchHandler> {
|
|
9
10
|
readonly runtime = "bun";
|
|
10
11
|
readonly options: Server["options"];
|
|
@@ -17,6 +18,5 @@ declare class BunServer implements Server<BunFetchHandler> {
|
|
|
17
18
|
ready(): Promise<this>;
|
|
18
19
|
close(closeAll?: boolean): Promise<void>;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
21
|
//#endregion
|
|
22
22
|
export { FastResponse, FastURL, serve };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "
|
|
2
|
-
import { wrapFetch } from "
|
|
1
|
+
import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
|
|
2
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/bun.ts
|
|
5
5
|
const FastResponse = Response;
|
|
@@ -24,7 +24,7 @@ var BunServer = class {
|
|
|
24
24
|
runtime: {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
value: {
|
|
27
|
-
|
|
27
|
+
name: "bun",
|
|
28
28
|
bun: { server }
|
|
29
29
|
}
|
|
30
30
|
},
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Server, ServerOptions } from "
|
|
1
|
+
import { Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
2
|
import * as CF from "@cloudflare/workers-types";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/cloudflare.d.ts
|
|
5
5
|
declare const FastURL: typeof globalThis.URL;
|
|
6
6
|
declare const FastResponse: typeof globalThis.Response;
|
|
7
7
|
declare function serve(options: ServerOptions): Server<CF.ExportedHandlerFetchHandler>;
|
|
8
|
-
|
|
9
8
|
//#endregion
|
|
10
9
|
export { FastResponse, FastURL, serve };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { wrapFetch } from "
|
|
2
|
-
import { errorPlugin } from "
|
|
1
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
2
|
+
import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/cloudflare.ts
|
|
5
5
|
const FastURL = URL;
|
|
@@ -24,7 +24,7 @@ var CloudflareServer = class {
|
|
|
24
24
|
Object.defineProperties(request, { runtime: {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
value: {
|
|
27
|
-
|
|
27
|
+
name: "cloudflare",
|
|
28
28
|
cloudflare: {
|
|
29
29
|
env,
|
|
30
30
|
context
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { DenoFetchHandler, Server, ServerOptions } from "
|
|
2
|
-
import { FastURL$
|
|
1
|
+
import { DenoFetchHandler, Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/deno.d.ts
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
|
6
6
|
declare function serve(options: ServerOptions): DenoServer;
|
|
7
|
+
// https://docs.deno.com/api/deno/~/Deno.serve
|
|
7
8
|
declare class DenoServer implements Server<DenoFetchHandler> {
|
|
8
9
|
#private;
|
|
9
10
|
readonly runtime = "deno";
|
|
@@ -17,6 +18,5 @@ declare class DenoServer implements Server<DenoFetchHandler> {
|
|
|
17
18
|
ready(): Promise<Server>;
|
|
18
19
|
close(): Promise<void | undefined>;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
21
|
//#endregion
|
|
22
22
|
export { FastResponse, FastURL, serve };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "
|
|
2
|
-
import { wrapFetch } from "
|
|
1
|
+
import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
|
|
2
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/deno.ts
|
|
5
5
|
const FastResponse = Response;
|
|
@@ -26,7 +26,7 @@ var DenoServer = class {
|
|
|
26
26
|
runtime: {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
value: {
|
|
29
|
-
|
|
29
|
+
name: "deno",
|
|
30
30
|
deno: {
|
|
31
31
|
info,
|
|
32
32
|
server: this.deno?.server
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Server, ServerOptions } from "
|
|
1
|
+
import { Server, ServerOptions } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/generic.d.ts
|
|
4
4
|
declare const FastURL: typeof globalThis.URL;
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
|
6
6
|
declare function serve(options: ServerOptions): Server;
|
|
7
|
-
|
|
8
7
|
//#endregion
|
|
9
8
|
export { FastResponse, FastURL, serve };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { wrapFetch } from "
|
|
2
|
-
import { errorPlugin } from "
|
|
1
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
2
|
+
import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/generic.ts
|
|
5
5
|
const FastURL = URL;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "
|
|
2
|
-
import { FastURL$
|
|
1
|
+
import { FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
|
+
import { FastURL$2 as FastURL } from "../_chunks/_url-0kFTYgtJ.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
|
-
|
|
15
14
|
//#endregion
|
|
16
15
|
//#region src/adapters/_node/headers.d.ts
|
|
17
16
|
declare const NodeRequestHeaders: {
|
|
@@ -26,7 +25,6 @@ declare const NodeResponseHeaders: {
|
|
|
26
25
|
res: NodeServerResponse;
|
|
27
26
|
}): globalThis.Headers;
|
|
28
27
|
};
|
|
29
|
-
|
|
30
28
|
//#endregion
|
|
31
29
|
//#region src/adapters/_node/response.d.ts
|
|
32
30
|
type NodeResponse = InstanceType<typeof NodeResponse>;
|
|
@@ -45,11 +43,9 @@ declare const NodeResponse: {
|
|
|
45
43
|
};
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
|
-
|
|
49
46
|
//#endregion
|
|
50
47
|
//#region src/adapters/node.d.ts
|
|
51
48
|
declare function serve(options: ServerOptions): Server;
|
|
52
49
|
declare function toNodeHandler(fetchHandler: FetchHandler): NodeHttpHandler;
|
|
53
|
-
|
|
54
50
|
//#endregion
|
|
55
51
|
export { NodeResponse as FastResponse, FastURL, NodeRequest, NodeRequestHeaders, NodeResponse, NodeResponseHeaders, serve, toNodeHandler };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "
|
|
2
|
-
import { wrapFetch } from "
|
|
3
|
-
import { errorPlugin } from "
|
|
1
|
+
import { FastURL$1 as FastURL, fmtURL, printListening, resolvePortAndHost, resolveTLSOptions } from "../_chunks/_url-Dsik4Hgl.mjs";
|
|
2
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
3
|
+
import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
|
|
4
4
|
import { splitSetCookieString } from "cookie-es";
|
|
5
5
|
|
|
6
6
|
//#region src/adapters/_node/send.ts
|
|
@@ -426,7 +426,12 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
426
426
|
return this._node.req.method || "GET";
|
|
427
427
|
}
|
|
428
428
|
get signal() {
|
|
429
|
-
if (!this.#abortSignal)
|
|
429
|
+
if (!this.#abortSignal) {
|
|
430
|
+
this.#abortSignal = new AbortController();
|
|
431
|
+
this._node.req.once("close", () => {
|
|
432
|
+
this.#abortSignal?.abort();
|
|
433
|
+
});
|
|
434
|
+
}
|
|
430
435
|
return this.#abortSignal.signal;
|
|
431
436
|
}
|
|
432
437
|
get bodyUsed() {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Server, ServerOptions, ServerRequest } from "
|
|
1
|
+
import { Server, ServerOptions, ServerRequest } from "../_chunks/types-CAoaOHnD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/service-worker.d.ts
|
|
4
4
|
declare const FastURL: typeof globalThis.URL;
|
|
5
5
|
declare const FastResponse: typeof globalThis.Response;
|
|
6
6
|
type ServiceWorkerHandler = (request: ServerRequest, event: FetchEvent) => Response | Promise<Response>;
|
|
7
7
|
declare function serve(options: ServerOptions): Server<ServiceWorkerHandler>;
|
|
8
|
-
|
|
9
8
|
//#endregion
|
|
10
9
|
export { FastResponse, FastURL, ServiceWorkerHandler, serve };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { wrapFetch } from "
|
|
2
|
-
import { errorPlugin } from "
|
|
1
|
+
import { wrapFetch } from "../_chunks/_middleware-Bz7WmB2e.mjs";
|
|
2
|
+
import { errorPlugin } from "../_chunks/_plugins-CDyQtZq-.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/adapters/service-worker.ts
|
|
5
5
|
const FastURL = URL;
|
|
@@ -27,7 +27,7 @@ var ServiceWorkerServer = class {
|
|
|
27
27
|
Object.defineProperties(request, { runtime: {
|
|
28
28
|
enumerable: true,
|
|
29
29
|
value: {
|
|
30
|
-
|
|
30
|
+
name: "service-worker",
|
|
31
31
|
serviceWorker: { event }
|
|
32
32
|
}
|
|
33
33
|
} });
|
package/dist/types.d.mts
CHANGED
|
@@ -1,228 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import * as NodeHttp2 from "node:http2";
|
|
4
|
-
import * as NodeNet from "node:net";
|
|
5
|
-
import * as Bun from "bun";
|
|
6
|
-
import * as CF from "@cloudflare/workers-types";
|
|
7
|
-
|
|
8
|
-
//#region src/types.d.ts
|
|
9
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
10
|
-
/**
|
|
11
|
-
* Faster URL constructor with lazy access to pathname and search params (For Node, Deno, and Bun).
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Web fetch compatible request handler
|
|
16
|
-
*/
|
|
17
|
-
type ServerHandler = (request: ServerRequest) => MaybePromise<Response>;
|
|
18
|
-
type ServerMiddleware = (request: ServerRequest, next: () => Response | Promise<Response>) => Response | Promise<Response>;
|
|
19
|
-
type ServerPlugin = (server: Server) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Server options
|
|
22
|
-
*/
|
|
23
|
-
interface ServerOptions {
|
|
24
|
-
/**
|
|
25
|
-
* The fetch handler handles incoming requests.
|
|
26
|
-
*/
|
|
27
|
-
fetch: ServerHandler;
|
|
28
|
-
/**
|
|
29
|
-
* Handle lifecycle errors.
|
|
30
|
-
*
|
|
31
|
-
* @note This handler will set built-in Bun and Deno error handler.
|
|
32
|
-
*/
|
|
33
|
-
error?: ErrorHandler;
|
|
34
|
-
/**
|
|
35
|
-
* Server middleware handlers to run before the main fetch handler.
|
|
36
|
-
*/
|
|
37
|
-
middleware?: ServerMiddleware[];
|
|
38
|
-
/**
|
|
39
|
-
* Server plugins.
|
|
40
|
-
*/
|
|
41
|
-
plugins?: ServerPlugin[];
|
|
42
|
-
/**
|
|
43
|
-
* If set to `true`, server will not start listening automatically.
|
|
44
|
-
*/
|
|
45
|
-
manual?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* The port server should be listening to.
|
|
48
|
-
*
|
|
49
|
-
* Default is read from `PORT` environment variable or will be `3000`.
|
|
50
|
-
*
|
|
51
|
-
* **Tip:** You can set the port to `0` to use a random port.
|
|
52
|
-
*/
|
|
53
|
-
port?: string | number;
|
|
54
|
-
/**
|
|
55
|
-
* The hostname (IP or resolvable host) server listener should bound to.
|
|
56
|
-
*
|
|
57
|
-
* When not provided, server with listen to all network interfaces by default.
|
|
58
|
-
*
|
|
59
|
-
* **Important:** If you are running a server that is not expected to be exposed to the network, use `hostname: "localhost"`.
|
|
60
|
-
*/
|
|
61
|
-
hostname?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Enabling this option allows multiple processes to bind to the same port, which is useful for load balancing.
|
|
64
|
-
*
|
|
65
|
-
* **Note:** Despite Node.js built-in behavior that has `exclusive` flag (opposite of `reusePort`) enabled by default, srvx uses non-exclusive mode for consistency.
|
|
66
|
-
*/
|
|
67
|
-
reusePort?: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* The protocol to use for the server.
|
|
70
|
-
*
|
|
71
|
-
* Possible values are `http` and `https`.
|
|
72
|
-
*
|
|
73
|
-
* If `protocol` is not set, Server will use `http` as the default protocol or `https` if both `tls.cert` and `tls.key` options are provided.
|
|
74
|
-
*/
|
|
75
|
-
protocol?: "http" | "https";
|
|
76
|
-
/**
|
|
77
|
-
* If set to `true`, server will not print the listening address.
|
|
78
|
-
*/
|
|
79
|
-
silent?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* TLS server options.
|
|
82
|
-
*/
|
|
83
|
-
tls?: {
|
|
84
|
-
/**
|
|
85
|
-
* File path or inlined TLS certificate in PEM format (required).
|
|
86
|
-
*/
|
|
87
|
-
cert?: string;
|
|
88
|
-
/**
|
|
89
|
-
* File path or inlined TLS private key in PEM format (required).
|
|
90
|
-
*/
|
|
91
|
-
key?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Passphrase for the private key (optional).
|
|
94
|
-
*/
|
|
95
|
-
passphrase?: string;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Node.js server options.
|
|
99
|
-
*/
|
|
100
|
-
node?: (NodeHttp$1.ServerOptions | NodeHttps.ServerOptions | NodeHttp2.ServerOptions) & NodeNet.ListenOptions & {
|
|
101
|
-
http2?: boolean;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Bun server options
|
|
105
|
-
*
|
|
106
|
-
* @docs https://bun.sh/docs/api/http
|
|
107
|
-
*/
|
|
108
|
-
bun?: Omit<Bun.ServeOptions | Bun.TLSServeOptions, "fetch">;
|
|
109
|
-
/**
|
|
110
|
-
* Deno server options
|
|
111
|
-
*
|
|
112
|
-
* @docs https://docs.deno.com/api/deno/~/Deno.serve
|
|
113
|
-
*/
|
|
114
|
-
deno?: Deno.ServeOptions;
|
|
115
|
-
/**
|
|
116
|
-
* Service worker options
|
|
117
|
-
*/
|
|
118
|
-
serviceWorker?: {
|
|
119
|
-
/**
|
|
120
|
-
* The path to the service worker file to be registered.
|
|
121
|
-
*/
|
|
122
|
-
url?: string;
|
|
123
|
-
/**
|
|
124
|
-
* The scope of the service worker.
|
|
125
|
-
*
|
|
126
|
-
*/
|
|
127
|
-
scope?: string;
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
interface Server<Handler = ServerHandler> {
|
|
131
|
-
/**
|
|
132
|
-
* Current runtime name
|
|
133
|
-
*/
|
|
134
|
-
readonly runtime: "node" | "deno" | "bun" | "cloudflare" | "service-worker" | "generic";
|
|
135
|
-
/**
|
|
136
|
-
* Server options
|
|
137
|
-
*/
|
|
138
|
-
readonly options: ServerOptions & {
|
|
139
|
-
middleware: ServerMiddleware[];
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Server URL address.
|
|
143
|
-
*/
|
|
144
|
-
readonly url?: string;
|
|
145
|
-
/**
|
|
146
|
-
* Node.js context.
|
|
147
|
-
*/
|
|
148
|
-
readonly node?: {
|
|
149
|
-
server?: NodeHttp$1.Server | NodeHttp2.Http2Server;
|
|
150
|
-
handler: (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Bun context.
|
|
154
|
-
*/
|
|
155
|
-
readonly bun?: {
|
|
156
|
-
server?: Bun.Server;
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Deno context.
|
|
160
|
-
*/
|
|
161
|
-
readonly deno?: {
|
|
162
|
-
server?: Deno.HttpServer;
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* Server fetch handler
|
|
166
|
-
*/
|
|
167
|
-
readonly fetch: Handler;
|
|
168
|
-
/**
|
|
169
|
-
* Returns a promise that resolves when the server is ready.
|
|
170
|
-
*/
|
|
171
|
-
ready(): Promise<Server<Handler>>;
|
|
172
|
-
/**
|
|
173
|
-
* Stop listening to prevent new connections from being accepted.
|
|
174
|
-
*
|
|
175
|
-
* By default, it does not cancel in-flight requests or websockets. That means it may take some time before all network activity stops.
|
|
176
|
-
*
|
|
177
|
-
* @param closeActiveConnections Immediately terminate in-flight requests, websockets, and stop accepting new connections.
|
|
178
|
-
* @default false
|
|
179
|
-
*/
|
|
180
|
-
close(closeActiveConnections?: boolean): Promise<void>;
|
|
181
|
-
}
|
|
182
|
-
interface ServerRuntimeContext {
|
|
183
|
-
name: "node" | "deno" | "bun" | "cloudflare" | (string & {});
|
|
184
|
-
/**
|
|
185
|
-
* Underlying Node.js server request info.
|
|
186
|
-
*/
|
|
187
|
-
node?: {
|
|
188
|
-
req: NodeServerRequest;
|
|
189
|
-
res?: NodeServerResponse;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Underlying Deno server request info.
|
|
193
|
-
*/
|
|
194
|
-
deno?: {
|
|
195
|
-
info: Deno.ServeHandlerInfo<Deno.NetAddr>;
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* Underlying Bun server request context.
|
|
199
|
-
*/
|
|
200
|
-
bun?: {
|
|
201
|
-
server: Bun.Server;
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* Underlying Cloudflare request context.
|
|
205
|
-
*/
|
|
206
|
-
cloudflare?: {
|
|
207
|
-
env: unknown;
|
|
208
|
-
context: CF.ExecutionContext;
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
interface ServerRequest extends Request {
|
|
212
|
-
/**
|
|
213
|
-
* Runtime specific request context.
|
|
214
|
-
*/
|
|
215
|
-
runtime?: ServerRuntimeContext;
|
|
216
|
-
/**
|
|
217
|
-
* IP address of the client.
|
|
218
|
-
*/
|
|
219
|
-
ip?: string | undefined;
|
|
220
|
-
}
|
|
221
|
-
type FetchHandler = (request: Request) => Response | Promise<Response>;
|
|
222
|
-
type ErrorHandler = (error: unknown) => Response | Promise<Response>;
|
|
223
|
-
type BunFetchHandler = (request: Request, server?: Bun.Server) => Response | Promise<Response>;
|
|
224
|
-
type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
|
|
225
|
-
type NodeServerRequest = NodeHttp$1.IncomingMessage | NodeHttp2.Http2ServerRequest;
|
|
226
|
-
type NodeServerResponse = NodeHttp$1.ServerResponse | NodeHttp2.Http2ServerResponse;
|
|
227
|
-
type NodeHttpHandler = (req: NodeServerRequest, res: NodeServerResponse) => void | Promise<void>; //#endregion
|
|
228
|
-
export { BunFetchHandler, DenoFetchHandler, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerOptions, ServerRequest };
|
|
1
|
+
import { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve } from "./_chunks/types-CAoaOHnD.mjs";
|
|
2
|
+
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRuntimeContext, serve };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "srvx",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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",
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
"type": "module",
|
|
10
10
|
"exports": {
|
|
11
11
|
"./types": "./dist/types.d.mts",
|
|
12
|
-
"./deno": "./dist/deno.mjs",
|
|
13
|
-
"./bun": "./dist/bun.mjs",
|
|
14
|
-
"./node": "./dist/node.mjs",
|
|
15
|
-
"./cloudflare": "./dist/cloudflare.mjs",
|
|
16
|
-
"./generic": "./dist/generic.mjs",
|
|
17
|
-
"./service-worker": "./dist/service-worker.mjs",
|
|
12
|
+
"./deno": "./dist/adapters/deno.mjs",
|
|
13
|
+
"./bun": "./dist/adapters/bun.mjs",
|
|
14
|
+
"./node": "./dist/adapters/node.mjs",
|
|
15
|
+
"./cloudflare": "./dist/adapters/cloudflare.mjs",
|
|
16
|
+
"./generic": "./dist/adapters/generic.mjs",
|
|
17
|
+
"./service-worker": "./dist/adapters/service-worker.mjs",
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/types.d.mts",
|
|
20
|
-
"deno": "./dist/deno.mjs",
|
|
21
|
-
"bun": "./dist/bun.mjs",
|
|
22
|
-
"workerd": "./dist/cloudflare.mjs",
|
|
23
|
-
"browser": "./dist/service-worker.mjs",
|
|
24
|
-
"node": "./dist/node.mjs",
|
|
25
|
-
"default": "./dist/generic.mjs"
|
|
20
|
+
"deno": "./dist/adapters/deno.mjs",
|
|
21
|
+
"bun": "./dist/adapters/bun.mjs",
|
|
22
|
+
"workerd": "./dist/adapters/cloudflare.mjs",
|
|
23
|
+
"browser": "./dist/adapters/service-worker.mjs",
|
|
24
|
+
"node": "./dist/adapters/node.mjs",
|
|
25
|
+
"default": "./dist/adapters/generic.mjs"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"types": "./dist/types.d.mts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"play:cf": "pnpx wrangler dev playground/app.mjs",
|
|
45
45
|
"play:deno": "deno run -A playground/app.mjs",
|
|
46
46
|
"play:mkcert": "openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt -days 365 -subj /CN=srvx.local",
|
|
47
|
-
"play:node": "node playground/app.mjs",
|
|
47
|
+
"play:node": "pnpm node-ts playground/app.mjs",
|
|
48
48
|
"play:sw": "pnpm build && pnpx serve playground",
|
|
49
49
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
50
50
|
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
@@ -57,29 +57,31 @@
|
|
|
57
57
|
"cookie-es": "^2.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@cloudflare/workers-types": "^4.
|
|
61
|
-
"@hono/node-server": "^1.14.
|
|
60
|
+
"@cloudflare/workers-types": "^4.20250525.0",
|
|
61
|
+
"@hono/node-server": "^1.14.3",
|
|
62
62
|
"@mitata/counters": "^0.0.8",
|
|
63
63
|
"@mjackson/node-fetch-server": "^0.6.1",
|
|
64
|
-
"@types/bun": "^1.2.
|
|
64
|
+
"@types/bun": "^1.2.14",
|
|
65
65
|
"@types/deno": "^2.3.0",
|
|
66
|
-
"@types/node": "^22.15.
|
|
66
|
+
"@types/node": "^22.15.21",
|
|
67
67
|
"@types/node-forge": "^1.3.11",
|
|
68
|
-
"@types/serviceworker": "^0.0.
|
|
69
|
-
"@vitest/coverage-v8": "^3.1.
|
|
68
|
+
"@types/serviceworker": "^0.0.135",
|
|
69
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
70
|
+
"@whatwg-node/server": "^0.10.10",
|
|
70
71
|
"automd": "^0.4.0",
|
|
71
72
|
"changelogen": "^0.6.1",
|
|
72
|
-
"eslint": "^9.
|
|
73
|
+
"eslint": "^9.27.0",
|
|
73
74
|
"eslint-config-unjs": "^0.4.2",
|
|
74
|
-
"execa": "^9.
|
|
75
|
+
"execa": "^9.6.0",
|
|
75
76
|
"get-port-please": "^3.1.2",
|
|
76
77
|
"mitata": "^1.0.34",
|
|
77
78
|
"node-forge": "^1.3.1",
|
|
78
|
-
"obuild": "^0.0
|
|
79
|
+
"obuild": "^0.2.0",
|
|
79
80
|
"prettier": "^3.5.3",
|
|
81
|
+
"tslib": "^2.8.1",
|
|
80
82
|
"typescript": "^5.8.3",
|
|
81
|
-
"undici": "^7.
|
|
82
|
-
"vitest": "^3.1.
|
|
83
|
+
"undici": "^7.10.0",
|
|
84
|
+
"vitest": "^3.1.4"
|
|
83
85
|
},
|
|
84
86
|
"packageManager": "pnpm@10.11.0",
|
|
85
87
|
"engines": {
|
|
File without changes
|
|
File without changes
|