srvx 0.11.8 → 0.11.9

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.
@@ -1,4 +1,5 @@
1
1
  import { a as green, i as gray, n as bold, s as red } from "./_utils.mjs";
2
+ //#region src/_middleware.ts
2
3
  function wrapFetch(server) {
3
4
  const fetchHandler = server.options.fetch;
4
5
  const middleware = server.options.middleware || [];
@@ -8,6 +9,8 @@ function callMiddleware(request, fetchHandler, middleware, index) {
8
9
  if (index === middleware.length) return fetchHandler(request);
9
10
  return middleware[index](request, () => callMiddleware(request, fetchHandler, middleware, index + 1));
10
11
  }
12
+ //#endregion
13
+ //#region src/_plugins.ts
11
14
  const errorPlugin = (server) => {
12
15
  const errorHandler = server.options.error;
13
16
  if (!errorHandler) return;
@@ -53,4 +56,5 @@ const gracefulShutdownPlugin = (server) => {
53
56
  };
54
57
  for (const sig of ["SIGINT", "SIGTERM"]) globalThis.process.on(sig, shutdown);
55
58
  };
59
+ //#endregion
56
60
  export { gracefulShutdownPlugin as n, wrapFetch as r, errorPlugin as t };
@@ -1,3 +1,4 @@
1
+ //#region src/_inherit.ts
1
2
  function lazyInherit(target, source, sourceKey) {
2
3
  for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
3
4
  if (key === "constructor") continue;
@@ -25,6 +26,9 @@ function lazyInherit(target, source, sourceKey) {
25
26
  if (modified) Object.defineProperty(target, key, desc);
26
27
  }
27
28
  }
29
+ //#endregion
30
+ //#region src/_url.ts
31
+ const _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^\x80-\uffff]/i;
28
32
  /**
29
33
  * URL wrapper with fast paths to access to the following props:
30
34
  *
@@ -52,6 +56,7 @@ const FastURL = /* @__PURE__ */ (() => {
52
56
  #pos;
53
57
  constructor(url) {
54
58
  if (typeof url === "string") this.#href = url;
59
+ else if (_needsNormRE.test(url.pathname)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
55
60
  else {
56
61
  this.#protocol = url.protocol;
57
62
  this.#host = url.host;
@@ -137,4 +142,5 @@ const FastURL = /* @__PURE__ */ (() => {
137
142
  Object.setPrototypeOf(FastURL, NativeURL);
138
143
  return FastURL;
139
144
  })();
145
+ //#endregion
140
146
  export { lazyInherit as n, FastURL as t };
@@ -1,3 +1,4 @@
1
+ //#region src/cli/_utils.ts
1
2
  const noColor = /* @__PURE__ */ (() => {
2
3
  const env = globalThis.process?.env ?? {};
3
4
  return env.NO_COLOR === "1" || env.TERM === "dumb";
@@ -12,4 +13,5 @@ const magenta = /* @__PURE__ */ _c(35);
12
13
  const cyan = /* @__PURE__ */ _c(36);
13
14
  const gray = /* @__PURE__ */ _c(90);
14
15
  const url = (title, url) => noColor ? `[${title}](${url})` : `\u001B]8;;${url}\u001B\\${title}\u001B]8;;\u001B\\`;
16
+ //#endregion
15
17
  export { green as a, url as c, gray as i, yellow as l, bold as n, magenta as o, cyan as r, red as s, blue as t };
@@ -1,3 +1,4 @@
1
+ //#region src/_utils.ts
1
2
  function resolvePortAndHost(opts) {
2
3
  const _port = opts.port ?? globalThis.process?.env.PORT ?? 3e3;
3
4
  const port = typeof _port === "number" ? _port : Number.parseInt(_port, 10);
@@ -67,4 +68,5 @@ function createWaitUntil() {
67
68
  }
68
69
  };
69
70
  }
71
+ //#endregion
70
72
  export { resolveTLSOptions as a, resolvePortAndHost as i, fmtURL as n, printListening as r, createWaitUntil as t };
@@ -1,5 +1,6 @@
1
1
  import "../_chunks/_utils.mjs";
2
2
  import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
+ //#region src/adapters/_aws/utils.ts
3
4
  function awsRequest(event, context) {
4
5
  const req = new Request(awsEventURL(event), {
5
6
  method: awsEventMethod(event),
@@ -250,6 +251,8 @@ function createMockContext() {
250
251
  succeed: () => {}
251
252
  };
252
253
  }
254
+ //#endregion
255
+ //#region src/adapters/aws-lambda.ts
253
256
  function toLambdaHandler(options) {
254
257
  const server = new AWSLambdaServer(options);
255
258
  return (event, context) => server.fetch(event, context);
@@ -290,4 +293,5 @@ var AWSLambdaServer = class {
290
293
  return Promise.resolve();
291
294
  }
292
295
  };
296
+ //#endregion
293
297
  export { handleLambdaEvent, handleLambdaEventWithStream, invokeLambdaHandler, toLambdaHandler };
@@ -2,6 +2,7 @@ import "../_chunks/_utils.mjs";
2
2
  import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils2.mjs";
4
4
  import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
5
+ //#region src/adapters/bun.ts
5
6
  const FastResponse = Response;
6
7
  function serve(options) {
7
8
  return new BunServer(options);
@@ -84,4 +85,5 @@ var BunServer = class {
84
85
  await Promise.all([this.#wait?.wait(), Promise.resolve(this.bun?.server?.stop(closeAll))]);
85
86
  }
86
87
  };
88
+ //#endregion
87
89
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,6 @@
1
1
  import "../_chunks/_utils.mjs";
2
2
  import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
+ //#region src/adapters/bunny.ts
3
4
  const FastURL = URL;
4
5
  const FastResponse = Response;
5
6
  function serve(options) {
@@ -52,4 +53,5 @@ var BunnyServer = class {
52
53
  return Promise.resolve();
53
54
  }
54
55
  };
56
+ //#endregion
55
57
  export { FastResponse, FastURL, serve };
@@ -1,5 +1,6 @@
1
1
  import "../_chunks/_utils.mjs";
2
2
  import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
+ //#region src/adapters/cloudflare.ts
3
4
  const FastURL = URL;
4
5
  const FastResponse = Response;
5
6
  function serve(options) {
@@ -55,4 +56,5 @@ var CloudflareServer = class {
55
56
  return Promise.resolve();
56
57
  }
57
58
  };
59
+ //#endregion
58
60
  export { FastResponse, FastURL, serve };
@@ -2,6 +2,7 @@ import "../_chunks/_utils.mjs";
2
2
  import { t as FastURL } from "../_chunks/_url.mjs";
3
3
  import { a as resolveTLSOptions, i as resolvePortAndHost, n as fmtURL, r as printListening, t as createWaitUntil } from "../_chunks/_utils2.mjs";
4
4
  import { n as gracefulShutdownPlugin, r as wrapFetch } from "../_chunks/_plugins.mjs";
5
+ //#region src/adapters/deno.ts
5
6
  const FastResponse = Response;
6
7
  function serve(options) {
7
8
  return new DenoServer(options);
@@ -93,4 +94,5 @@ var DenoServer = class {
93
94
  await Promise.all([this.#wait?.wait(), Promise.resolve(this.deno?.server?.shutdown())]);
94
95
  }
95
96
  };
97
+ //#endregion
96
98
  export { FastResponse, FastURL, serve };
@@ -1,6 +1,7 @@
1
1
  import "../_chunks/_utils.mjs";
2
2
  import { t as createWaitUntil } from "../_chunks/_utils2.mjs";
3
3
  import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
4
+ //#region src/adapters/generic.ts
4
5
  const FastURL = URL;
5
6
  const FastResponse = Response;
6
7
  function serve(options) {
@@ -35,4 +36,5 @@ var GenericServer = class {
35
36
  await this.#wait.wait();
36
37
  }
37
38
  };
39
+ //#endregion
38
40
  export { FastResponse, FastURL, serve };
@@ -6,6 +6,7 @@ import nodeHTTP, { IncomingMessage, ServerResponse } from "node:http";
6
6
  import { Duplex, PassThrough, Readable } from "node:stream";
7
7
  import nodeHTTPS from "node:https";
8
8
  import nodeHTTP2 from "node:http2";
9
+ //#region src/adapters/_node/send.ts
9
10
  async function sendNodeResponse(nodeRes, webRes) {
10
11
  if (!webRes) {
11
12
  nodeRes.statusCode = 500;
@@ -63,6 +64,8 @@ function streamBody(stream, nodeRes) {
63
64
  nodeRes.off("error", streamCancel);
64
65
  });
65
66
  }
67
+ //#endregion
68
+ //#region src/adapters/_node/url.ts
66
69
  /**
67
70
  * Validates an HTTP Host header value (domain, IPv4, or bracketed IPv6) with optional port.
68
71
  * Intended for preliminary filtering invalid values like "localhost:3000/foobar?"
@@ -99,6 +102,8 @@ var NodeRequestURL = class extends FastURL {
99
102
  this.#req.url = this._url.pathname + this._url.search;
100
103
  }
101
104
  };
105
+ //#endregion
106
+ //#region src/adapters/_node/headers.ts
102
107
  const NodeRequestHeaders = /* @__PURE__ */ (() => {
103
108
  const NativeHeaders = globalThis.Headers;
104
109
  class Headers {
@@ -160,6 +165,8 @@ const NodeRequestHeaders = /* @__PURE__ */ (() => {
160
165
  Object.setPrototypeOf(Headers.prototype, NativeHeaders.prototype);
161
166
  return Headers;
162
167
  })();
168
+ //#endregion
169
+ //#region src/adapters/_node/request.ts
163
170
  const NodeRequest = /* @__PURE__ */ (() => {
164
171
  const NativeRequest = globalThis.Request;
165
172
  class Request {
@@ -299,6 +306,8 @@ function readBody(req) {
299
306
  req.on("data", onData).once("end", onEnd).once("error", onError);
300
307
  });
301
308
  }
309
+ //#endregion
310
+ //#region src/adapters/_node/response.ts
302
311
  /**
303
312
  * Fast Response for Node.js runtime
304
313
  *
@@ -412,6 +421,8 @@ const NodeResponse = /* @__PURE__ */ (() => {
412
421
  Object.setPrototypeOf(NodeResponse.prototype, NativeResponse.prototype);
413
422
  return NodeResponse;
414
423
  })();
424
+ //#endregion
425
+ //#region src/adapters/_node/web/socket.ts
415
426
  /**
416
427
  * Events:
417
428
  * - Readable (req from client): readable => data => end (push(null)) => error => close
@@ -532,6 +543,8 @@ var WebRequestSocket = class extends Duplex {
532
543
  cb(err ?? void 0);
533
544
  }
534
545
  };
546
+ //#endregion
547
+ //#region src/adapters/_node/web/incoming.ts
535
548
  var WebIncomingMessage = class extends IncomingMessage {
536
549
  constructor(req, socket) {
537
550
  super(socket);
@@ -550,6 +563,8 @@ var WebIncomingMessage = class extends IncomingMessage {
550
563
  });
551
564
  }
552
565
  };
566
+ //#endregion
567
+ //#region src/adapters/_node/call.ts
553
568
  function callNodeHandler(handler, req) {
554
569
  const isMiddleware = handler.length > 2;
555
570
  const nodeCtx = req.runtime?.node;
@@ -593,6 +608,8 @@ function callNodeHandler(handler, req) {
593
608
  }
594
609
  });
595
610
  }
611
+ //#endregion
612
+ //#region src/adapters/_node/web/response.ts
596
613
  var WebServerResponse = class extends ServerResponse {
597
614
  #socket;
598
615
  constructor(req, socket) {
@@ -631,6 +648,8 @@ var WebServerResponse = class extends ServerResponse {
631
648
  });
632
649
  }
633
650
  };
651
+ //#endregion
652
+ //#region src/adapters/_node/web/fetch.ts
634
653
  /**
635
654
  * Calls a Node.js HTTP Request handler with a Fetch API Request object and returns a Response object.
636
655
  *
@@ -662,6 +681,8 @@ async function fetchNodeHandler(handler, req) {
662
681
  });
663
682
  }
664
683
  }
684
+ //#endregion
685
+ //#region src/adapters/_node/adapter.ts
665
686
  /**
666
687
  * Converts a Fetch API handler to a Node.js HTTP handler.
667
688
  */
@@ -697,6 +718,8 @@ function assignFnName(target, source, suffix) {
697
718
  Object.defineProperty(target, "name", { value: `${source.name}${suffix}` });
698
719
  } catch {}
699
720
  }
721
+ //#endregion
722
+ //#region src/adapters/node.ts
700
723
  function serve(options) {
701
724
  return new NodeServer(options);
702
725
  }
@@ -790,4 +813,5 @@ var NodeServer = class {
790
813
  })]);
791
814
  }
792
815
  };
816
+ //#endregion
793
817
  export { NodeResponse as FastResponse, NodeResponse, FastURL, NodeRequest, fetchNodeHandler, patchGlobalRequest, sendNodeResponse, serve, toFetchHandler, toNodeHandler };
@@ -1,5 +1,6 @@
1
1
  import "../_chunks/_utils.mjs";
2
2
  import { r as wrapFetch, t as errorPlugin } from "../_chunks/_plugins.mjs";
3
+ //#region src/adapters/service-worker.ts
3
4
  const FastURL = URL;
4
5
  const FastResponse = Response;
5
6
  const isBrowserWindow = typeof window !== "undefined" && typeof navigator !== "undefined";
@@ -74,4 +75,5 @@ var ServiceWorkerServer = class {
74
75
  } else if (isServiceWorker) await self.registration.unregister();
75
76
  }
76
77
  };
78
+ //#endregion
77
79
  export { FastResponse, FastURL, serve };
package/dist/cli.mjs CHANGED
@@ -6,6 +6,7 @@ import { fork } from "node:child_process";
6
6
  import { createReadStream, existsSync, statSync } from "node:fs";
7
7
  import { dirname, relative, resolve } from "node:path";
8
8
  import { Readable } from "node:stream";
9
+ //#region src/cli/serve.ts
9
10
  const NO_ENTRY_ERROR = "No server entry or public directory found";
10
11
  async function cliServe(cliOpts) {
11
12
  try {
@@ -88,6 +89,8 @@ function printInfo(cliOpts, loaded) {
88
89
  console.log(gray(`${bold(gray("◇"))} Static files: ${staticInfo}`));
89
90
  console.log("");
90
91
  }
92
+ //#endregion
93
+ //#region src/cli/fetch.ts
91
94
  async function cliFetch(cliOpts) {
92
95
  const stdin = cliOpts.stdin || process.stdin;
93
96
  const stdout = cliOpts.stdout || process.stdout;
@@ -177,11 +180,15 @@ function getResponseFormat(res) {
177
180
  encoding: contentType.includes("charset=") ? contentType.split("charset=")[1].split(";")[0].trim() : "utf8"
178
181
  };
179
182
  }
183
+ //#endregion
184
+ //#region src/cli/_meta.ts
180
185
  const srvxMeta = {
181
186
  name: "srvx",
182
- version: "0.11.8",
187
+ version: "0.11.9",
183
188
  description: "Universal Server."
184
189
  };
190
+ //#endregion
191
+ //#region src/cli/usage.ts
185
192
  function usage(mainOpts) {
186
193
  const command = mainOpts.usage?.command || "srvx";
187
194
  const name = mainOpts.meta?.name || srvxMeta.name;
@@ -247,6 +254,8 @@ ${mainOpts.usage?.docs ? `➤ ${url("Documentation", mainOpts.usage.docs)}` : ""
247
254
  ${mainOpts.usage?.issues ? `➤ ${url("Report issues", mainOpts.usage.issues)}` : ""}
248
255
  `.trim();
249
256
  }
257
+ //#endregion
258
+ //#region src/cli/main.ts
250
259
  async function main(mainOpts) {
251
260
  const args = process.argv.slice(2);
252
261
  const cliOpts = parseArgs$1(args);
@@ -423,4 +432,5 @@ function runtime() {
423
432
  else if (process.versions.deno) return `deno ${process.versions.deno}`;
424
433
  else return `node ${process.versions.node}`;
425
434
  }
435
+ //#endregion
426
436
  export { cliFetch, main };
package/dist/loader.mjs CHANGED
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
3
3
  import { resolve } from "node:path";
4
4
  import * as nodeHTTP$1 from "node:http";
5
5
  import { EventEmitter } from "node:events";
6
+ //#region src/loader.ts
6
7
  const defaultExts = [
7
8
  ".mjs",
8
9
  ".js",
@@ -135,4 +136,5 @@ var StubNodeServer = class extends EventEmitter {
135
136
  return this;
136
137
  }
137
138
  };
139
+ //#endregion
138
140
  export { defaultEntries, defaultExts, loadServerEntry };
package/dist/log.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { a as green, i as gray, l as yellow, n as bold, s as red, t as blue } from "./_chunks/_utils.mjs";
2
+ //#region src/log.ts
2
3
  const statusColors = {
3
4
  1: blue,
4
5
  2: green,
@@ -14,4 +15,5 @@ const log = (_options = {}) => {
14
15
  return res;
15
16
  };
16
17
  };
18
+ //#endregion
17
19
  export { log };
package/dist/static.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { t as FastURL } from "./_chunks/_url.mjs";
2
2
  import { createReadStream } from "node:fs";
3
- import { extname, join, resolve } from "node:path";
3
+ import { extname, join, resolve, sep } from "node:path";
4
4
  import { readFile, stat } from "node:fs/promises";
5
5
  import { FastResponse } from "srvx";
6
6
  import { createBrotliCompress, createGzip } from "node:zlib";
7
+ //#region src/static.ts
7
8
  const COMMON_MIME_TYPES = {
8
9
  ".html": "text/html",
9
10
  ".htm": "text/html",
@@ -28,7 +29,7 @@ const COMMON_MIME_TYPES = {
28
29
  ".pdf": "application/pdf"
29
30
  };
30
31
  const serveStatic = (options) => {
31
- const dir = resolve(options.dir) + "/";
32
+ const dir = resolve(options.dir) + sep;
32
33
  const methods = new Set((options.methods || ["GET", "HEAD"]).map((m) => m.toUpperCase()));
33
34
  return async (req, next) => {
34
35
  if (!methods.has(req.method)) return next();
@@ -71,4 +72,5 @@ const serveStatic = (options) => {
71
72
  return next();
72
73
  };
73
74
  };
75
+ //#endregion
74
76
  export { serveStatic };
package/dist/tracing.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/tracing.ts
1
2
  /**
2
3
  *
3
4
  * @experimental Channel names, event types and config options may change in future releases.
@@ -52,4 +53,5 @@ function tracingPlugin(opts = {}) {
52
53
  }
53
54
  };
54
55
  }
56
+ //#endregion
55
57
  export { tracingPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "srvx",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "Universal Server.",
5
5
  "homepage": "https://srvx.h3.dev",
6
6
  "license": "MIT",
@@ -59,18 +59,18 @@
59
59
  "vitest": "vitest"
60
60
  },
61
61
  "devDependencies": {
62
- "@cloudflare/workers-types": "^4.20260304.0",
63
- "@hono/node-server": "^1.19.9",
62
+ "@cloudflare/workers-types": "^4.20260307.1",
63
+ "@hono/node-server": "^1.19.11",
64
64
  "@mitata/counters": "^0.0.8",
65
65
  "@mjackson/node-fetch-server": "^0.7.0",
66
- "@types/aws-lambda": "^8.10.160",
67
- "@types/bun": "^1.3.9",
66
+ "@types/aws-lambda": "^8.10.161",
67
+ "@types/bun": "^1.3.10",
68
68
  "@types/deno": "^2.5.0",
69
69
  "@types/express": "^5.0.6",
70
- "@types/node": "^25.3.0",
70
+ "@types/node": "^25.3.5",
71
71
  "@types/node-forge": "^1.3.14",
72
- "@types/serviceworker": "^0.0.192",
73
- "@typescript/native-preview": "^7.0.0-dev.20260225.1",
72
+ "@types/serviceworker": "^0.0.193",
73
+ "@typescript/native-preview": "7.0.0-dev.20260309.1",
74
74
  "@vitest/coverage-v8": "^4.0.18",
75
75
  "@whatwg-node/server": "^0.10.18",
76
76
  "automd": "^0.4.3",
@@ -78,15 +78,15 @@
78
78
  "eslint-config-unjs": "^0.6.2",
79
79
  "execa": "^9.6.1",
80
80
  "express": "^5.2.1",
81
- "fastify": "^5.7.4",
81
+ "fastify": "^5.8.2",
82
82
  "get-port-please": "^3.2.0",
83
83
  "mdbox": "^0.1.1",
84
84
  "mitata": "^1.0.34",
85
85
  "node-forge": "^1.3.3",
86
- "obuild": "^0.4.31",
87
- "oxfmt": "^0.35.0",
88
- "oxlint": "^1.50.0",
89
- "srvx-release": "npm:srvx@^0.11.7",
86
+ "obuild": "^0.4.32",
87
+ "oxfmt": "^0.36.0",
88
+ "oxlint": "^1.51.0",
89
+ "srvx-release": "npm:srvx@^0.11.8",
90
90
  "tslib": "^2.8.1",
91
91
  "typescript": "^5.9.3",
92
92
  "undici": "^7.22.0",