Skip to content

feat(dev): use runtime-native server for dev listener - #4832

Merged
pi0 merged 2 commits into
mainfrom
feat/runtime-native-dev
Oct 18, 2026
Merged

pi0 merged 2 commits into
mainfrom
feat/runtime-native-dev

Conversation

@pi0x

@pi0x pi0x commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #4816

The dev listener used srvx/node, so under Bun and Deno it went through the node:http compat layer. It now uses srvx, which picks Bun.serve() / Deno.serve().

Node.js: no behavior change. Upgrades still go through raw socket proxying (upgrade() / proxyUpgrade()), and devProxy still uses the full httpxy proxy server.

Other runtimes:

  • WebSocket upgrades go through a crossws plugin. The new resolveWebSocketHooks(req) returns createWebSocketProxy hooks for a matching devProxy rule or for the dev worker address (TCP or ws+unix://). Client headers such as cookies are forwarded.
  • devProxy HTTP falls back to httpxy proxyFetch when there is no Node.js request. This also makes nitro.fetch() work for devProxy routes.
  • Static asset streams become web streams.

fetch plus resolveWebSocketHooks(req) is now a runtime-agnostic surface. That should make other hosts easier later, such as a browser dev server. env-runner itself still relies on Node.js APIs.

Trade-offs on Bun/Deno

  • The WebSocket proxy accepts the connection before reaching the upstream. An upstream rejection shows up as close code 1011, not as an HTTP status.
  • Only a subset of devProxy options apply (documented in docs/3.config).
  • Worker WebSocket upgrades with the miniflare runner (Cloudflare presets) are rejected with a 503 and a hint to use Node.js, because the runner reports no address to dial.

Tests

  • New test/unit/dev-proxy-web.test.ts covers the proxyFetch fallback and the crossws WebSocket proxy.
  • The existing nitro dev (bun) case in test/vite/websocket.test.ts now runs on the native path.
  • Checked manually under Node, Bun and Deno: routes, static files, devProxy HTTP and WebSocket, and worker WebSocket.

🤖 Generated with AI assistant

Listen with `srvx` so Bun and Deno use their native servers. WebSocket upgrades on
non-Node runtimes go through crossws proxy hooks, and `devProxy` falls back to httpxy
`proxyFetch` when there is no Node.js request.
@pi0x
pi0x requested a review from pi0 as a code owner October 18, 2026 00:38
@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 18, 2026 1:07am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b32b066c-dd0a-418e-93c8-7aee69fce2c0
📥 Commits

Reviewing files that changed from the base of the PR and between dc8fcdb and 7f2d55e.

📒 Files selected for processing: 6
  • docs/3.config/0.index.md
  • src/dev/_proxy.ts
  • src/dev/_ws.ts
  • src/dev/app.ts
  • src/dev/server.ts
  • test/unit/dev-proxy-web.test.ts
+----------------------------------------------------------------+
| Fully armed and operationally intelligent code reviewer bunny. |
+----------------------------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4832

commit: 7f2d55e

- merge target query, keep `//` paths, support IPv6 and TLS object targets
- forward the client address in `x-forwarded-for` and only set basic auth when missing
- reject worker websocket handshakes when the runner has no usable address
- use crossws bun/deno adapters directly and load the websocket proxy on demand
@pi0
pi0 merged commit ed90537 into main Oct 18, 2026
14 of 15 checks passed
@pi0
pi0 deleted the feat/runtime-native-dev branch October 18, 2026 01:09

This branch was successfully deployed

1 active deployment
Preview — 7f2d55ec Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dev server listener should use native runtime serve

2 participants