srvx 0.9.7 → 0.10.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/README.md +1 -0
- package/dist/_chunks/{_plugins-ZJvYKoy9.mjs → _plugins.mjs} +1 -1
- package/dist/_chunks/{_url-COjYRiX5.mjs → _url.mjs} +1 -1
- package/dist/_chunks/{call-BLKVUMn3.mjs → call.mjs} +1 -1
- package/dist/_chunks/call2.mjs +3 -0
- package/dist/_chunks/{types-CpzLEZLT.d.mts → types.d.mts} +13 -3
- package/dist/adapters/bun.d.mts +2 -2
- package/dist/adapters/bun.mjs +3 -5
- package/dist/adapters/cloudflare.d.mts +1 -1
- package/dist/adapters/cloudflare.mjs +1 -2
- package/dist/adapters/deno.d.mts +2 -2
- package/dist/adapters/deno.mjs +3 -5
- package/dist/adapters/generic.d.mts +1 -1
- package/dist/adapters/generic.mjs +2 -3
- package/dist/adapters/node.d.mts +11 -3
- package/dist/adapters/node.mjs +46 -29
- package/dist/adapters/service-worker.d.mts +1 -1
- package/dist/adapters/service-worker.mjs +1 -2
- package/dist/cli.mjs +2 -2
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +1 -1
- package/dist/static.d.mts +1 -1
- package/dist/static.mjs +1 -2
- package/dist/tracing.d.mts +42 -0
- package/dist/tracing.mjs +58 -0
- package/dist/types.d.mts +2 -2
- package/package.json +18 -17
- package/dist/_chunks/call-BlEaeO5P.mjs +0 -4
- /package/dist/_chunks/{_color-Kmne9cay.mjs → _color.mjs} +0 -0
- /package/dist/_chunks/{_inherit-D99WuBbX.mjs → _inherit.mjs} +0 -0
- /package/dist/_chunks/{_url-C-JHG430.d.mts → _url.d.mts} +0 -0
- /package/dist/_chunks/{_utils-CIBojyNO.mjs → _utils.mjs} +0 -0
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ $ bunx --bun srvx
|
|
|
60
60
|
| `jsx` | [examples/jsx](https://github.com/h3js/srvx/tree/main/examples/jsx/) | `npx giget gh:h3js/srvx/examples/jsx srvx-jsx` |
|
|
61
61
|
| `node-handler` | [examples/node-handler](https://github.com/h3js/srvx/tree/main/examples/node-handler/) | `npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler` |
|
|
62
62
|
| `service-worker` | [examples/service-worker](https://github.com/h3js/srvx/tree/main/examples/service-worker/) | `npx giget gh:h3js/srvx/examples/service-worker srvx-service-worker` |
|
|
63
|
+
| `tracing` | [examples/tracing](https://github.com/h3js/srvx/tree/main/examples/tracing/) | `npx giget gh:h3js/srvx/examples/tracing srvx-tracing` |
|
|
63
64
|
| `websocket` | [examples/websocket](https://github.com/h3js/srvx/tree/main/examples/websocket/) | `npx giget gh:h3js/srvx/examples/websocket srvx-websocket` |
|
|
64
65
|
|
|
65
66
|
<!-- /automd -->
|
|
@@ -239,6 +239,12 @@ interface ServerRequestContext {
|
|
|
239
239
|
[key: string]: unknown;
|
|
240
240
|
}
|
|
241
241
|
interface ServerRequest extends Request {
|
|
242
|
+
/**
|
|
243
|
+
* Access to Node.js native instance of request.
|
|
244
|
+
*
|
|
245
|
+
* See https://srvx.h3.dev/guide/node#noderequest
|
|
246
|
+
*/
|
|
247
|
+
_request?: Request;
|
|
242
248
|
/**
|
|
243
249
|
* Access to the parsed URL
|
|
244
250
|
*/
|
|
@@ -266,8 +272,12 @@ type BunFetchHandler = (request: Request, server?: Bun.Server<any>) => Response
|
|
|
266
272
|
type DenoFetchHandler = (request: Request, info?: Deno.ServeHandlerInfo<Deno.NetAddr>) => Response | Promise<Response>;
|
|
267
273
|
type NodeServerRequest = NodeHttp.IncomingMessage | NodeHttp2.Http2ServerRequest;
|
|
268
274
|
type NodeServerResponse = NodeHttp.ServerResponse | NodeHttp2.Http2ServerResponse;
|
|
269
|
-
type
|
|
270
|
-
type
|
|
275
|
+
type NodeHttp1Handler = (req: NodeHttp.IncomingMessage, res: NodeHttp.ServerResponse) => void | Promise<void>;
|
|
276
|
+
type NodeHttp2Handler = (req: NodeHttp2.Http2ServerRequest, res: NodeHttp2.Http2ServerResponse) => void | Promise<void>;
|
|
277
|
+
type NodeHttpHandler = NodeHttp1Handler | NodeHttp2Handler;
|
|
278
|
+
type NodeHTTP1Middleware = (req: NodeHttp.IncomingMessage, res: NodeHttp.ServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
|
|
279
|
+
type NodeHTTP2Middleware = (req: NodeHttp2.Http2ServerRequest, res: NodeHttp2.Http2ServerResponse, next: (error?: Error) => void) => unknown | Promise<unknown>;
|
|
280
|
+
type NodeHTTPMiddleware = NodeHTTP1Middleware | NodeHTTP2Middleware;
|
|
271
281
|
type CloudflareFetchHandler = CF.ExportedHandlerFetchHandler;
|
|
272
282
|
//#endregion
|
|
273
|
-
export {
|
|
283
|
+
export { ServerRuntimeContext as C, ServerRequestContext as S, ServerHandler as _, FastResponse as a, ServerPlugin as b, NodeHTTP1Middleware as c, NodeHttp1Handler as d, NodeHttp2Handler as f, Server as g, NodeServerResponse as h, ErrorHandler as i, NodeHTTP2Middleware as l, NodeServerRequest as m, CloudflareFetchHandler as n, FastURL as o, NodeHttpHandler as p, DenoFetchHandler as r, FetchHandler as s, BunFetchHandler as t, NodeHTTPMiddleware as u, ServerMiddleware as v, serve as w, ServerRequest as x, ServerOptions as y };
|
package/dist/adapters/bun.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as FastURL } from "../_chunks/_url
|
|
1
|
+
import { g as Server, t as BunFetchHandler, y as ServerOptions } from "../_chunks/types.mjs";
|
|
2
|
+
import { t as FastURL } from "../_chunks/_url.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,8 +1,6 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
import "../_chunks/
|
|
3
|
-
import {
|
|
4
|
-
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
|
|
5
|
-
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins-ZJvYKoy9.mjs";
|
|
1
|
+
import { t as FastURL } from "../_chunks/_url.mjs";
|
|
2
|
+
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
|
|
3
|
+
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
|
|
6
4
|
|
|
7
5
|
//#region src/adapters/bun.ts
|
|
8
6
|
const FastResponse = Response;
|
package/dist/adapters/deno.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as FastURL } from "../_chunks/_url
|
|
1
|
+
import { g as Server, r as DenoFetchHandler, y as ServerOptions } from "../_chunks/types.mjs";
|
|
2
|
+
import { t as FastURL } from "../_chunks/_url.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,8 +1,6 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
import "../_chunks/
|
|
3
|
-
import {
|
|
4
|
-
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils-CIBojyNO.mjs";
|
|
5
|
-
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins-ZJvYKoy9.mjs";
|
|
1
|
+
import { t as FastURL } from "../_chunks/_url.mjs";
|
|
2
|
+
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
|
|
3
|
+
import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
|
|
6
4
|
|
|
7
5
|
//#region src/adapters/deno.ts
|
|
8
6
|
const FastResponse = Response;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
import { t as
|
|
3
|
-
import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
|
|
1
|
+
import { t as createWaitUntil } from "../_chunks/_utils.mjs";
|
|
2
|
+
import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/adapters/generic.ts
|
|
6
5
|
const FastURL = URL;
|
package/dist/adapters/node.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as FastURL } from "../_chunks/_url
|
|
1
|
+
import { g as Server, h as NodeServerResponse, m as NodeServerRequest, p as NodeHttpHandler, s as FetchHandler, x as ServerRequest, y as ServerOptions } from "../_chunks/types.mjs";
|
|
2
|
+
import { t as FastURL } from "../_chunks/_url.mjs";
|
|
3
3
|
import { Readable } from "node:stream";
|
|
4
4
|
|
|
5
5
|
//#region src/adapters/_node/request.d.ts
|
|
@@ -10,6 +10,14 @@ type NodeRequestContext = {
|
|
|
10
10
|
declare const NodeRequest: {
|
|
11
11
|
new (nodeCtx: NodeRequestContext): ServerRequest;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Undici uses an incompatible Request constructor depending on private property accessors.
|
|
15
|
+
*
|
|
16
|
+
* This utility, patches global Request to support `new Request(req)` in Node.js.
|
|
17
|
+
*
|
|
18
|
+
* Alternatively you can use `new Request(req._request || req)` instead of patching global Request.
|
|
19
|
+
*/
|
|
20
|
+
declare function patchGlobalRequest(): typeof Request;
|
|
13
21
|
//#endregion
|
|
14
22
|
//#region src/adapters/_node/response.d.ts
|
|
15
23
|
type PreparedNodeResponseBody = string | Buffer | Uint8Array | DataView | ReadableStream | Readable | undefined | null;
|
|
@@ -67,4 +75,4 @@ declare function toFetchHandler(handler: NodeHttpHandler & AdapterMeta): FetchHa
|
|
|
67
75
|
//#region src/adapters/node.d.ts
|
|
68
76
|
declare function serve(options: ServerOptions): Server;
|
|
69
77
|
//#endregion
|
|
70
|
-
export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
|
|
78
|
+
export { type AdapterMeta, NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
|
package/dist/adapters/node.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import { n as NodeResponse, t as callNodeHandler } from "../_chunks/call-BLKVUMn3.mjs";
|
|
1
|
+
import { t as lazyInherit } from "../_chunks/_inherit.mjs";
|
|
2
|
+
import { t as FastURL } from "../_chunks/_url.mjs";
|
|
3
|
+
import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils.mjs";
|
|
4
|
+
import { n as gracefulShutdownPlugin, r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
|
|
5
|
+
import { n as NodeResponse, t as callNodeHandler } from "../_chunks/call.mjs";
|
|
7
6
|
import nodeHTTP, { IncomingMessage, ServerResponse } from "node:http";
|
|
8
7
|
import { Duplex, Readable } from "node:stream";
|
|
9
8
|
import nodeHTTPS from "node:https";
|
|
@@ -165,20 +164,7 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
|
|
|
165
164
|
//#endregion
|
|
166
165
|
//#region src/adapters/_node/request.ts
|
|
167
166
|
const NodeRequest = /* @__PURE__ */ (() => {
|
|
168
|
-
const NativeRequest = globalThis
|
|
169
|
-
const PatchedRequest = class Request$1 extends NativeRequest {
|
|
170
|
-
static _srvx = true;
|
|
171
|
-
static [Symbol.hasInstance](instance) {
|
|
172
|
-
if (this === PatchedRequest) return instance instanceof NativeRequest;
|
|
173
|
-
else return Object.prototype.isPrototypeOf.call(this.prototype, instance);
|
|
174
|
-
}
|
|
175
|
-
constructor(input, options) {
|
|
176
|
-
if (typeof input === "object" && "_request" in input) input = input._request;
|
|
177
|
-
if ((options?.body)?.getReader !== void 0) options.duplex ??= "half";
|
|
178
|
-
super(input, options);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
if (!globalThis.Request._srvx) globalThis.Request = PatchedRequest;
|
|
167
|
+
const NativeRequest = globalThis.Request;
|
|
182
168
|
class Request {
|
|
183
169
|
runtime;
|
|
184
170
|
#req;
|
|
@@ -221,12 +207,18 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
221
207
|
get _abortController() {
|
|
222
208
|
if (!this.#abortController) {
|
|
223
209
|
this.#abortController = new AbortController();
|
|
224
|
-
const req = this
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
};
|
|
210
|
+
const { req, res } = this.runtime.node;
|
|
211
|
+
const abortController = this.#abortController;
|
|
212
|
+
const abort = (err) => abortController.abort?.(err);
|
|
228
213
|
req.once("error", abort);
|
|
229
|
-
|
|
214
|
+
if (res) res.once("close", () => {
|
|
215
|
+
const reqError = req.errored;
|
|
216
|
+
if (reqError) abort(reqError);
|
|
217
|
+
else if (!res.writableEnded) abort();
|
|
218
|
+
});
|
|
219
|
+
else req.once("close", () => {
|
|
220
|
+
if (!req.complete) abort();
|
|
221
|
+
});
|
|
230
222
|
}
|
|
231
223
|
return this.#abortController;
|
|
232
224
|
}
|
|
@@ -252,11 +244,13 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
252
244
|
}
|
|
253
245
|
get _request() {
|
|
254
246
|
if (!this.#request) {
|
|
255
|
-
|
|
247
|
+
const body = this.body;
|
|
248
|
+
this.#request = new NativeRequest(this.url, {
|
|
256
249
|
method: this.method,
|
|
257
250
|
headers: this.headers,
|
|
258
|
-
|
|
259
|
-
|
|
251
|
+
signal: this._abortController.signal,
|
|
252
|
+
body,
|
|
253
|
+
duplex: body ? "half" : void 0
|
|
260
254
|
});
|
|
261
255
|
this.#headers = void 0;
|
|
262
256
|
this.#bodyStream = void 0;
|
|
@@ -268,6 +262,29 @@ const NodeRequest = /* @__PURE__ */ (() => {
|
|
|
268
262
|
Object.setPrototypeOf(Request.prototype, NativeRequest.prototype);
|
|
269
263
|
return Request;
|
|
270
264
|
})();
|
|
265
|
+
/**
|
|
266
|
+
* Undici uses an incompatible Request constructor depending on private property accessors.
|
|
267
|
+
*
|
|
268
|
+
* This utility, patches global Request to support `new Request(req)` in Node.js.
|
|
269
|
+
*
|
|
270
|
+
* Alternatively you can use `new Request(req._request || req)` instead of patching global Request.
|
|
271
|
+
*/
|
|
272
|
+
function patchGlobalRequest() {
|
|
273
|
+
const NativeRequest = globalThis[Symbol.for("srvx.nativeRequest")] ??= globalThis.Request;
|
|
274
|
+
const PatchedRequest = class Request extends NativeRequest {
|
|
275
|
+
static _srvx = true;
|
|
276
|
+
static [Symbol.hasInstance](instance) {
|
|
277
|
+
if (this === PatchedRequest) return instance instanceof NativeRequest;
|
|
278
|
+
else return Object.prototype.isPrototypeOf.call(this.prototype, instance);
|
|
279
|
+
}
|
|
280
|
+
constructor(input, options) {
|
|
281
|
+
if (typeof input === "object" && "_request" in input) input = input._request;
|
|
282
|
+
super(input, options);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
if (!globalThis.Request._srvx) globalThis.Request = PatchedRequest;
|
|
286
|
+
return PatchedRequest;
|
|
287
|
+
}
|
|
271
288
|
function readBody(req) {
|
|
272
289
|
return new Promise((resolve, reject) => {
|
|
273
290
|
const chunks = [];
|
|
@@ -632,4 +649,4 @@ var NodeServer = class {
|
|
|
632
649
|
};
|
|
633
650
|
|
|
634
651
|
//#endregion
|
|
635
|
-
export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
|
|
652
|
+
export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as Server, x as ServerRequest, y as ServerOptions } from "../_chunks/types.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/adapters/service-worker.d.ts
|
|
4
4
|
declare const FastURL: typeof globalThis.URL;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import "../_chunks/
|
|
2
|
-
import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins-ZJvYKoy9.mjs";
|
|
1
|
+
import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
|
|
3
2
|
|
|
4
3
|
//#region src/adapters/service-worker.ts
|
|
5
4
|
const FastURL = URL;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as green, c as url, i as gray, l as yellow, n as bold, o as magenta, r as cyan, s as red } from "./_chunks/_color
|
|
1
|
+
import { a as green, c as url, i as gray, l as yellow, n as bold, o as magenta, r as cyan, s as red } from "./_chunks/_color.mjs";
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import * as nodeHTTP$1 from "node:http";
|
|
@@ -135,7 +135,7 @@ async function loadEntry(opts) {
|
|
|
135
135
|
const nodeHandler = listenHandler || (typeof mod.default === "function" ? mod.default : void 0);
|
|
136
136
|
if (nodeHandler) {
|
|
137
137
|
_legacyNode = true;
|
|
138
|
-
const { callNodeHandler } = await import("./_chunks/
|
|
138
|
+
const { callNodeHandler } = await import("./_chunks/call2.mjs");
|
|
139
139
|
fetchHandler = (webReq) => callNodeHandler(nodeHandler, webReq);
|
|
140
140
|
}
|
|
141
141
|
}
|
package/dist/log.d.mts
CHANGED
package/dist/log.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_color
|
|
1
|
+
import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_color.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/log.ts
|
|
4
4
|
const statusColors = {
|
package/dist/static.d.mts
CHANGED
package/dist/static.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import "./_chunks/
|
|
2
|
-
import { t as FastURL } from "./_chunks/_url-COjYRiX5.mjs";
|
|
1
|
+
import { t as FastURL } from "./_chunks/_url.mjs";
|
|
3
2
|
import { extname, join, resolve } from "node:path";
|
|
4
3
|
import { createReadStream } from "node:fs";
|
|
5
4
|
import { readFile, stat } from "node:fs/promises";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { b as ServerPlugin, g as Server, v as ServerMiddleware, x as ServerRequest } from "./_chunks/types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/tracing.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @experimental Channel names, event types and config options may change in future releases.
|
|
7
|
+
*/
|
|
8
|
+
type RequestEvent = {
|
|
9
|
+
server: Server;
|
|
10
|
+
request: ServerRequest;
|
|
11
|
+
middleware?: {
|
|
12
|
+
index: number;
|
|
13
|
+
handler: ServerMiddleware;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @experimental Channel names, event types and config options may change in future releases.
|
|
19
|
+
*
|
|
20
|
+
* Tracing plugin that adds diagnostics channel tracing to middleware and fetch handlers.
|
|
21
|
+
*
|
|
22
|
+
* This plugin wraps all middleware and the fetch handler with tracing instrumentation,
|
|
23
|
+
* allowing you to subscribe to `srvx.fetch` and `srvx.middleware` tracing channels.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { serve } from "srvx";
|
|
28
|
+
* import { tracingPlugin } from "srvx/tracing";
|
|
29
|
+
*
|
|
30
|
+
* const server = serve({
|
|
31
|
+
* fetch: (req) => new Response("OK"),
|
|
32
|
+
* middleware: [myMiddleware],
|
|
33
|
+
* plugins: [tracingPlugin()],
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function tracingPlugin(opts?: {
|
|
38
|
+
middleware?: boolean;
|
|
39
|
+
fetch?: boolean;
|
|
40
|
+
}): ServerPlugin;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { RequestEvent, tracingPlugin };
|
package/dist/tracing.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/tracing.ts
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @experimental Channel names, event types and config options may change in future releases.
|
|
5
|
+
*
|
|
6
|
+
* Tracing plugin that adds diagnostics channel tracing to middleware and fetch handlers.
|
|
7
|
+
*
|
|
8
|
+
* This plugin wraps all middleware and the fetch handler with tracing instrumentation,
|
|
9
|
+
* allowing you to subscribe to `srvx.fetch` and `srvx.middleware` tracing channels.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { serve } from "srvx";
|
|
14
|
+
* import { tracingPlugin } from "srvx/tracing";
|
|
15
|
+
*
|
|
16
|
+
* const server = serve({
|
|
17
|
+
* fetch: (req) => new Response("OK"),
|
|
18
|
+
* middleware: [myMiddleware],
|
|
19
|
+
* plugins: [tracingPlugin()],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function tracingPlugin(opts = {}) {
|
|
24
|
+
return (server) => {
|
|
25
|
+
const { tracingChannel } = globalThis.process?.getBuiltinModule?.("node:diagnostics_channel") || {};
|
|
26
|
+
if (!tracingChannel) return;
|
|
27
|
+
if (opts.fetch !== false) {
|
|
28
|
+
const fetchChannel = tracingChannel("srvx.fetch");
|
|
29
|
+
const originalFetch = server.options.fetch;
|
|
30
|
+
server.options.fetch = (request) => {
|
|
31
|
+
return fetchChannel.tracePromise(async () => await originalFetch(request), {
|
|
32
|
+
request,
|
|
33
|
+
server
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (opts.middleware !== false) {
|
|
38
|
+
const middlewareChannel = tracingChannel("srvx.middleware");
|
|
39
|
+
const wrappedMiddleware = server.options.middleware.map((handler, index) => {
|
|
40
|
+
const middleware = Object.freeze({
|
|
41
|
+
index,
|
|
42
|
+
handler
|
|
43
|
+
});
|
|
44
|
+
return (request, next) => {
|
|
45
|
+
return middlewareChannel.tracePromise(async () => await handler(request, next), {
|
|
46
|
+
request,
|
|
47
|
+
server,
|
|
48
|
+
middleware
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
server.options.middleware.splice(0, server.options.middleware.length, ...wrappedMiddleware);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { tracingPlugin };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTPMiddleware, NodeHttpHandler, NodeServerRequest, NodeServerResponse, Server, ServerHandler, ServerMiddleware, ServerOptions, ServerPlugin, ServerRequest, ServerRequestContext, ServerRuntimeContext, serve };
|
|
1
|
+
import { C as ServerRuntimeContext, S as ServerRequestContext, _ as ServerHandler, a as FastResponse, b as ServerPlugin, c as NodeHTTP1Middleware, d as NodeHttp1Handler, f as NodeHttp2Handler, g as Server, h as NodeServerResponse, i as ErrorHandler, l as NodeHTTP2Middleware, m as NodeServerRequest, n as CloudflareFetchHandler, o as FastURL, p as NodeHttpHandler, r as DenoFetchHandler, s as FetchHandler, t as BunFetchHandler, u as NodeHTTPMiddleware, v as ServerMiddleware, w as serve, x as ServerRequest, y as ServerOptions } from "./_chunks/types.mjs";
|
|
2
|
+
export { BunFetchHandler, CloudflareFetchHandler, DenoFetchHandler, ErrorHandler, FastResponse, FastURL, FetchHandler, NodeHTTP1Middleware, NodeHTTP2Middleware, NodeHTTPMiddleware, NodeHttp1Handler, NodeHttp2Handler, 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.
|
|
3
|
+
"version": "0.10.0",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"./cli": "./dist/cli.mjs",
|
|
18
18
|
"./static": "./dist/static.mjs",
|
|
19
19
|
"./log": "./dist/log.mjs",
|
|
20
|
+
"./tracing": "./dist/tracing.mjs",
|
|
20
21
|
".": {
|
|
21
22
|
"types": "./dist/types.d.mts",
|
|
22
23
|
"deno": "./dist/adapters/deno.mjs",
|
|
@@ -58,38 +59,38 @@
|
|
|
58
59
|
"srvx": "link:."
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@cloudflare/workers-types": "^4.
|
|
62
|
-
"@hono/node-server": "^1.19.
|
|
62
|
+
"@cloudflare/workers-types": "^4.20251230.0",
|
|
63
|
+
"@hono/node-server": "^1.19.7",
|
|
63
64
|
"@mitata/counters": "^0.0.8",
|
|
64
65
|
"@mjackson/node-fetch-server": "^0.7.0",
|
|
65
|
-
"@types/bun": "^1.3.
|
|
66
|
+
"@types/bun": "^1.3.5",
|
|
66
67
|
"@types/deno": "^2.5.0",
|
|
67
|
-
"@types/express": "^5.0.
|
|
68
|
-
"@types/node": "^
|
|
68
|
+
"@types/express": "^5.0.6",
|
|
69
|
+
"@types/node": "^25.0.3",
|
|
69
70
|
"@types/node-forge": "^1.3.14",
|
|
70
|
-
"@types/serviceworker": "^0.0.
|
|
71
|
-
"@vitest/coverage-v8": "^4.0.
|
|
71
|
+
"@types/serviceworker": "^0.0.172",
|
|
72
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
72
73
|
"@whatwg-node/server": "^0.10.17",
|
|
73
74
|
"automd": "^0.4.2",
|
|
74
75
|
"changelogen": "^0.6.2",
|
|
75
|
-
"eslint": "^9.39.
|
|
76
|
+
"eslint": "^9.39.2",
|
|
76
77
|
"eslint-config-unjs": "^0.5.0",
|
|
77
|
-
"execa": "^9.6.
|
|
78
|
-
"express": "^5.1
|
|
78
|
+
"execa": "^9.6.1",
|
|
79
|
+
"express": "^5.2.1",
|
|
79
80
|
"fastify": "^5.6.2",
|
|
80
81
|
"get-port-please": "^3.2.0",
|
|
81
82
|
"mdbox": "^0.1.1",
|
|
82
83
|
"mitata": "^1.0.34",
|
|
83
|
-
"node-forge": "^1.3.
|
|
84
|
-
"obuild": "^0.4.
|
|
85
|
-
"prettier": "^3.7.
|
|
86
|
-
"srvx-release": "npm:srvx@^0.9.
|
|
84
|
+
"node-forge": "^1.3.3",
|
|
85
|
+
"obuild": "^0.4.9",
|
|
86
|
+
"prettier": "^3.7.4",
|
|
87
|
+
"srvx-release": "npm:srvx@^0.9.8",
|
|
87
88
|
"tslib": "^2.8.1",
|
|
88
89
|
"typescript": "^5.9.3",
|
|
89
90
|
"undici": "^7.16.0",
|
|
90
|
-
"vitest": "4.0.
|
|
91
|
+
"vitest": "^4.0.16"
|
|
91
92
|
},
|
|
92
|
-
"packageManager": "pnpm@10.
|
|
93
|
+
"packageManager": "pnpm@10.26.2",
|
|
93
94
|
"engines": {
|
|
94
95
|
"node": ">=20.16.0"
|
|
95
96
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|