Detalhes do pacote

srvx

h3js106kMIT0.8.16

Universal Server API based on web platform standards. Works seamlessly with Deno, Bun and Node.js.

readme (leia-me)

λ srvx

npm version npm downloads install size

Universal Server based on web standards. Works with Deno, Bun and Node.js.

  • ✅ Zero dependency
  • ✅ Full featured CLI with watcher, error handler, serve static and logger
  • ✅ Seamless runtime integration with same API (handler and instance).
  • Node.js compatibility with up to ~96.98% native performance.
  • ✅ Zero overhead Deno and Bun support.

Quick start

export default {
  fetch(req: Request) {
    return Response.json({ hello: "world!" });
  },
};

Then, run the server using your favorite runtime:

# Node.js
$ npx srvx       # npm
$ pnpx srvx      # pnpm
$ yarn dlx srvx  # yarn

# Deno
$ deno -A npm:srvx

# Bun
$ bunx --bun srvx

👉 Visit the 📖 Documentation to learn more.

Starter Examples

➤ Online Playground

Example Source Try
elysia examples/elysia npx giget gh:h3js/srvx/examples/elysia srvx-elysia
express examples/express npx giget gh:h3js/srvx/examples/express srvx-express
fastify examples/fastify npx giget gh:h3js/srvx/examples/fastify srvx-fastify
h3 examples/h3 npx giget gh:h3js/srvx/examples/h3 srvx-h3
hello-world examples/hello-world npx giget gh:h3js/srvx/examples/hello-world srvx-hello-world
hono examples/hono npx giget gh:h3js/srvx/examples/hono srvx-hono
jsx examples/jsx npx giget gh:h3js/srvx/examples/jsx srvx-jsx
node-handler examples/node-handler npx giget gh:h3js/srvx/examples/node-handler srvx-node-handler
service-worker examples/service-worker npx giget gh:h3js/srvx/examples/service-worker srvx-service-worker
websocket examples/websocket npx giget gh:h3js/srvx/examples/websocket srvx-websocket

Contribution

  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Prepare stub mode using pnpm build --stub
  • Run interactive tests using pnpm dev

License

Published under the MIT license. Made by @pi0 and community 💛


🤖 auto updated with automd

changelog (log de mudanças)

Changelog

v0.8.16

compare changes

🩹 Fixes

  • cli: Correct middleware entry spread in serve function (#119)

📦 Build

  • Inline and export splitSetCookieString (#121)

❤️ Contributors

v0.8.15

compare changes

🩹 Fixes

  • Avoid inheriting constructor props (3ecb746)
  • node: Fix instance check against native Request after patching (c7e7b7f)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.14

compare changes

🚀 Enhancements

  • static: Support custom html renderer (604ee02)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.13

compare changes

🩹 Fixes

  • node: Sync FastURL pathname changes back to node req.url (#118)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.12

compare changes

🩹 Fixes

  • Safer access to process.getBuiltinModule (#117)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.11

compare changes

🚀 Enhancements

  • node: Support absolute paths in request line (#116)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.10

compare changes

🩹 Fixes

  • cli: Ensure child process is killed on exit (#114)

💅 Refactors

  • Reimplement FastURL (#112)
  • node: Rewrite NodeRequestURL based on FastURL (#113)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.9

compare changes

🩹 Fixes

  • node: Safer global Request patch (0e8d6da)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.8

compare changes

🩹 Fixes

  • node: Add back req.runtime (d1a148b)

💅 Refactors

  • node: Improve NodeRequest wrapper (#109)
  • node: Rewrite FastResponse (#110)
  • node: Avoid top level node: imports (d95ccb7)
  • node: Improve instance types (6e83952)

📖 Documentation

  • node: Provide async keyword (#107)

🏡 Chore

❤️ Contributors

v0.8.7

compare changes

🩹 Fixes

  • Add missing Server.serve type (#102)

🌊 Types

  • Declare optional ServerRequest.context (dc6f868)

🏡 Chore

  • Remove --experimental-strip-types in scripts (#105)

❤️ Contributors

v0.8.6

compare changes

🚀 Enhancements

  • cli: Support node.js and express handlers (#98)
  • cli: Support --import for custom loader (#99)
  • cli: Add server/index and jsx to defaults (7c65bd2)
  • cli: Set default NODE_ENV if not set before serve (cfbb3d6)

🩹 Fixes

  • Cli color resets (2ecc989)
  • cli: Exit if directory does not exists (3a94ac8)

💅 Refactors

  • logger: Better status colors (1643985)
  • cli: Improve info message (b97e4be)
  • cli: Always use sub process (82ecc00)

📖 Documentation

  • Fix typo (#96)

📦 Build

  • Lighter version injection to the bundle (6b78daa)

🏡 Chore

❤️ Contributors

v0.8.5

compare changes

🩹 Fixes

  • cli: Only add --experimental-strip-types flag to the safe range (d00aa93)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.4

compare changes

🚀 Enhancements

  • cli: Better hint for typescript support and Node.js version (8c710af)

🩹 Fixes

  • cli: Backward compatibility for ts support in older versions of Node.js 22 (9ee024b)

🏡 Chore

  • Update examples to use latest (338ea07)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.3

compare changes

🚀 Enhancements

  • Experimental cli (#91)
  • cli: Auto detect entry (6d9011d)
  • Basic serve static (#93)
  • Basic logger (#94)
  • cli: Support .env and .env.local in dev mode (4cdd246)

💅 Refactors

  • Convert serveStatic to middleware (c0f5bac)
  • Simplify cli usage (a30db56)
  • cli: Minor tweaks (0d86c7a)
  • cli: Support serve static only (20171c2)

📖 Documentation

  • Prepare for 0.8.3 release (#95)

📦 Build

🏡 Chore

🤖 CI

❤️ Contributors

  • Pooya Parsa (@pi0)
  • Hong Minhee (洪 民憙) (@dahlia)

v0.8.2

compare changes

🚀 Enhancements

  • node: Export sendNodeResponse (add088f)

🔥 Performance

  • node: Use fast response for .clone() in fast paths (e1e5a89)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.8.1

compare changes

🚀 Enhancements

  • cloudflare: Add request.ip (#89)

🩹 Fixes

  • node: Add unsupported getters (36615dc)

📖 Documentation

🏡 Chore

❤️ Contributors

v0.8.0

compare changes

💅 Refactors

  • Improve IsAny type helper (a0f5c7e)

📦 Build

  • ⚠️ Remove /types subpath (#83)

🌊 Types

  • Allow augmenting req.runtime.cloudflare.env (#84)

🏡 Chore

⚠️ Breaking Changes

  • ⚠️ Remove /types subpath (#83)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.7.5

compare changes

💅 Refactors

  • Remove unnecessary __PURE__ (699a100)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.7.4

compare changes

🚀 Enhancements

  • Universal request.waitUntil (#81)

📦 Build

  • Remove small side-effects from service-worker (2ed12a9)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.7.3

compare changes

🩹 Fixes

  • node: Only use req.headers in FastResponse when initialized (#79)

💅 Refactors

  • Include invalid header name in error message (d0bf7dc)

🏡 Chore

  • Add --watch to playground scripts (222580e)
  • Add erasableSyntaxOnly option to compiler options (#77)
  • Update undocs (5d263b1)
  • Build docs native dep (7c8b337)

❤️ Contributors

v0.7.2

compare changes

🚀 Enhancements

  • node: Call request abort signal (#76)

🩹 Fixes

📖 Documentation

  • guide/plugins: Make middleware functions asynchronous (#70)
  • guide/bundler: Improve bundle usage explanation (#73)

📦 Build

🏡 Chore

❤️ Contributors

v0.7.1

compare changes

📦 Build

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.7.0

compare changes

🚀 Enhancements

  • node: Support http2 (#58)
  • ⚠️ Top level middleware and simplified plugins (#67)
  • Clone options and init middleware: [] (16798c1)

🩹 Fixes

  • Add missing types for node.upgrade (7f66ac3)
  • url: Always invalidate cached values (059914d)

💅 Refactors

  • ⚠️ Remove experimental upgrade (#68)
  • ⚠️ Use process.getBuiltinModule for node (#69)
  • Move node compat to adapters/_node (e594009)

📦 Build

🏡 Chore

✅ Tests

  • Add wpt setter tests for FastURL (#66)
  • Add more coverage for FastURL (7e8ebd2)

⚠️ Breaking Changes

  • ⚠️ Top level middleware and simplified plugins (#67)
  • ⚠️ Remove experimental upgrade (#68)
  • ⚠️ Use process.getBuiltinModule for node (#69)

❤️ Contributors

v0.6.0

compare changes

🚀 Enhancements

  • ⚠️ Fetch middleware via plugins (#62)
  • Support upgrade hook (experimental) (#63)

🩹 Fixes

  • node: Handle additional response headers (#64)

💅 Refactors

  • ⚠️ Rename onError hook to error for consistency (471fe57)
  • ⚠️ Rename to FastURL and FastResponse exports (0fe9ed4)

🏡 Chore

⚠️ Breaking Changes

  • ⚠️ Fetch middleware via plugins (#62)
  • ⚠️ Rename onError hook to error for consistency (471fe57)
  • ⚠️ Rename to FastURL and FastResponse exports (0fe9ed4)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.5.2

compare changes

🚀 Enhancements

  • Fast URL for node, deno and bun (b5f5239)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.5.1

compare changes

🩹 Fixes

  • service-worker: Minor fixes (63a42b5)

🏡 Chore

  • Apply automated updates (248d0b5)
  • Update playground sw example to use cdn (b333bd4)
  • Fix node compat internal types (7862ab0)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.5.0

compare changes

🚀 Enhancements

  • Experimental service-worker adapter (#53)
  • service-worker: Self-register support (#55)
  • Generic adapter (#56)
  • ⚠️ Print listening url by default (#57)
  • Support HOST env for node, deno and bun (2d94e28)
  • Add runtime agnostic error handler (#48)

💅 Refactors

🏡 Chore

⚠️ Breaking Changes

  • ⚠️ Print listening url by default (#57)

❤️ Contributors

v0.4.0

compare changes

💅 Refactors

  • ⚠️ Use request.ip and request.runtime (#51)

🏡 Chore

  • Apply automated updates (59e28fa)

⚠️ Breaking Changes

  • ⚠️ Use request.ip and request.runtime (#51)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.3.0

compare changes

💅 Refactors

  • ⚠️ Move extended request context under request.x.* (#50)

📖 Documentation

  • Improve quick start (#49)

🏡 Chore

  • Update editorconfig to include typescript files (#47)

⚠️ Breaking Changes

  • ⚠️ Move extended request context under request.x.* (#50)

❤️ Contributors

v0.2.8

compare changes

🚀 Enhancements

  • node: Expose internal proxy classes (0cdfa22)
  • node: Support Response static methods (b9976a4)

🩹 Fixes

  • node: Use null for unset headers (#45)

💅 Refactors

  • Remove unused symbols (c726e40)
  • Accept node ctx for NodeResponseHeaders constructor (8fe9241)

📦 Build

  • Add types condition to top (82e7fcc)

🏡 Chore

  • Update node tests (#42)

❤️ Contributors

v0.2.7

compare changes

🚀 Enhancements

  • node: Expose node context to proxy interfaces (5f20d9e)

🩹 Fixes

  • node: Make sure response constructor name is Response (782ee13)
  • node: Make sure all proxies mimic global name and instance (5883995)
  • node: Use global Response for cloing (effa940)
  • node: Avoid conflict with undici prototype (40cacf2)

💅 Refactors

  • types: Fix typo for BunFetchHandler (#41)

📦 Build

❤️ Contributors

v0.2.6

compare changes

🚀 Enhancements

  • Support tls and protocol (#38)

🔥 Performance

  • adapters/node: Check req._hasBody once (978a27d)

🩹 Fixes

  • node: Flatten headers to handle node slow path (#40)

🏡 Chore

❤️ Contributors

v0.2.5

compare changes

🩹 Fixes

  • Fix Response type export (e8d25e9)
  • node: Set Response prototype for NodeFastResponse (2e6a8a0)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.2.4

compare changes

🩹 Fixes

  • Fix Response type export (e8d25e9)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.2.3

compare changes

🩹 Fixes

  • node: Use headers.entries when full Headers is set as init (7f8cac8)
  • node: Make req instanceof Request working (24b3f83)

📦 Build

  • Fix types export (#36)
  • Add types export for . (#37)

🏡 Chore

❤️ Contributors

v0.2.2

compare changes

🚀 Enhancements

  • node: Support node readable stream (bc72436)

🩹 Fixes

  • node: Don't send headers if already sent (bbf6b86)
  • Add Response export type (e63919b)
  • node: Use headers.entries when full Headers is set as init (7f8cac8)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.2.1

compare changes

🚀 Enhancements

🏡 Chore

  • Apply automated updates (5a1caf0)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.2.0

compare changes

🚀 Enhancements

💅 Refactors

  • ⚠️ Update exports (7153090)
  • ⚠️ Overhaul internal implementation (d444c74)

📦 Build

🏡 Chore

✅ Tests

🤖 CI

⚠️ Breaking Changes

  • ⚠️ Update exports (7153090)
  • ⚠️ Overhaul internal implementation (d444c74)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.4

compare changes

🩹 Fixes

  • node: Access req headers with lowerCase (#21)

💅 Refactors

  • node: Improve body streaming (#26)

🏡 Chore

❤️ Contributors

v0.1.3

compare changes

🚀 Enhancements

  • node: Add NodeFastResponse.bytes() (#16)
  • node: Add NodeRequestProxy.bytes() (07863f6)

🩹 Fixes

  • node: Compute hasBody when accessing req.body (a002185)
  • node: Body utils should respect buffer view offset (5e4ec69)

💅 Refactors

  • node: Expose request._url (8eb8f5d)

📖 Documentation

  • Minor tweaks (#9)

🏡 Chore

✅ Tests

  • Update ip regex (6885842)
  • Add additional tests for req body handling (e00b4c9)

❤️ Contributors

v0.1.2

compare changes

🚀 Enhancements

  • node: Add NodeFastResponse.bytes() (#16)
  • node: Add NodeRequestProxy.bytes() (07863f6)

📖 Documentation

  • Minor tweaks (#9)

🏡 Chore

❤️ Contributors

v0.1.1

🚀 Enhancements

🩹 Fixes

  • node: Send body with NodeFastResponse (ac689ef)

💅 Refactors

📖 Documentation

  • Remove extra await (#2)
  • Update diff explainer (fbd81af)

🏡 Chore

🤖 CI

❤️ Contributors