srvx 0.1.4 → 0.2.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/types.d.ts DELETED
@@ -1,175 +0,0 @@
1
- import * as NodeHttp from 'node:http';
2
- import * as NodeNet from 'node:net';
3
- import * as BunTypes from 'bun';
4
- import BunTypes__default from 'bun';
5
-
6
- declare abstract class Server {
7
- #private;
8
- /**
9
- * Current listening runtime name
10
- */
11
- abstract readonly runtime: "node" | "deno" | "bun";
12
- /**
13
- * Node.js listening server instance.
14
- */
15
- nodeServer?: NodeHttp.Server;
16
- /**
17
- * Bun listening server instance.
18
- */
19
- bunServer?: BunTypes__default.Server;
20
- /**
21
- * Deno listening server instance.
22
- */
23
- denoServer?: Deno.HttpServer;
24
- /**
25
- * Server options
26
- */
27
- options: Omit<ServerOptions, "fetch">;
28
- /**
29
- * Server fetch handler
30
- */
31
- fetch: ServerHandler;
32
- constructor(options: ServerOptions);
33
- protected abstract _listen(): void | Promise<void>;
34
- /**
35
- * Listening address (hostname or IP).
36
- */
37
- abstract readonly addr: string | null;
38
- /**
39
- * Listening port.
40
- */
41
- abstract readonly port: number | null;
42
- /**
43
- * Listening URL.
44
- */
45
- get url(): string | null;
46
- /**
47
- * Returns a promise that resolves when the server is ready.
48
- */
49
- ready(): Promise<Server>;
50
- /**
51
- * Stop listening to prevent new connections from being accepted.
52
- *
53
- * By default, it does not cancel in-flight requests or websockets. That means it may take some time before all network activity stops.
54
- *
55
- * @param closeActiveConnections Immediately terminate in-flight requests, websockets, and stop accepting new connections.
56
- * @default false
57
- */
58
- abstract close(closeActiveConnections?: boolean): void | Promise<void>;
59
- }
60
-
61
- type MaybePromise<T> = T | Promise<T>;
62
- /**
63
- * Create a new server instance.
64
- */
65
- declare function serve(options: ServerOptions): Server;
66
- /**
67
- * Web fetch compatible request handler
68
- */
69
- type ServerHandler = (request: xRequest) => MaybePromise<Response>;
70
- /**
71
- * Server options
72
- */
73
- interface ServerOptions {
74
- /**
75
- * The fetch handler handles incoming requests.
76
- */
77
- fetch: ServerHandler;
78
- /**
79
- * Server plugins
80
- */
81
- plugins?: (ServerPlugin | ServerPluginInstance)[];
82
- /**
83
- * The port server should be listening to.
84
- *
85
- * Default is read from `PORT` environment variable or will be `3000`.
86
- *
87
- * **Tip:** You can set the port to `0` to use a random port.
88
- */
89
- port?: string | number;
90
- /**
91
- * The hostname (IP or resolvable host) server listener should bound to.
92
- *
93
- * When not provided, server with listen to all network interfaces by default.
94
- *
95
- * **Important:** If you are running a server that is not expected to be exposed to the network, use `hostname: "localhost"`.
96
- */
97
- hostname?: string;
98
- /**
99
- * Enabling this option allows multiple processes to bind to the same port, which is useful for load balancing.
100
- *
101
- * **Note:** Despite Node.js built-in behavior that has `exclusive` flag (opposite of `reusePort`) enabled by default, srvx uses non-exclusive mode for consistency.
102
- */
103
- reusePort?: boolean;
104
- /**
105
- * If this option is enabled, `request.xRemoteAddress` will be available.
106
- * **Example:**
107
- *
108
- * ```js
109
- * serve({
110
- * port: 3000,
111
- * xRemoteAddress: true,
112
- * fetch: (request) =>
113
- * new Response(`Your ip address is ${request.xRemoteAddress}`),
114
- * });
115
- * ```
116
- * **Note:** In order to to provide cross-runtime consistency, a small wrapper function will be enabled for Deno and Bun runtimes if `xRemoteAddress` option is set.
117
- */
118
- xRemoteAddress?: boolean;
119
- /**
120
- * Node.js http server options.
121
- */
122
- node?: NodeHttp.ServerOptions & NodeNet.ListenOptions;
123
- /**
124
- * Bun server options
125
- *
126
- * @docs https://bun.sh/docs/api/http
127
- */
128
- bun?: Omit<BunTypes.ServeOptions, "fetch">;
129
- /**
130
- * Deno server options
131
- *
132
- * @docs https://docs.deno.com/api/deno/~/Deno.serve
133
- */
134
- deno?: Deno.ServeOptions;
135
- }
136
- type ServerPlugin = (server: Server) => MaybePromise<ServerPluginInstance>;
137
- interface ServerPluginInstance {
138
- /**
139
- * Plugin display name
140
- */
141
- name?: string;
142
- /**
143
- * Hook to allow running logic before user fetch handler
144
- * If an response value is returned, user fetch handler and the next plugins will be skipped.
145
- */
146
- request?: (request: xRequest) => MaybePromise<Response | void>;
147
- /**
148
- * Hook to allow running logic after user fetch handler
149
- * If a response value is returned, user response and the next plugins will be skipped.
150
- */
151
- response?: (request: xRequest, response: Response) => MaybePromise<void | Response>;
152
- }
153
- /**
154
- * https://developer.mozilla.org/en-US/docs/Web/API/Headers
155
- */
156
- type xHeaders = Omit<Headers, "count" | "toJSON" | "getAll">;
157
- /**
158
- * https://developer.mozilla.org/en-US/docs/Web/API/Request
159
- */
160
- interface xRequest extends Omit<Request, "headers" | "clone"> {
161
- headers: xHeaders;
162
- clone(): xRequest;
163
- xNode?: {
164
- req: NodeHttp.IncomingMessage;
165
- res: NodeHttp.ServerResponse;
166
- };
167
- /**
168
- * Remote address of the client.
169
- */
170
- xRemoteAddress?: string | null;
171
- /** Optional user context */
172
- xContext?: Record<string, unknown>;
173
- }
174
-
175
- export { Server, type ServerHandler, type ServerOptions, type ServerPlugin, type ServerPluginInstance, serve, type xHeaders, type xRequest };
package/dist/types.mjs DELETED
@@ -1 +0,0 @@
1
-