Skip to content

Run apps in production without the proxy hop (public listener, or virtual modules and plugins in self) #79

Closed

Description

@pi0x

Nitro is adding nitro serve / nitro start (nitrojs/nitro#4849) to run an app in production straight from its sources, without a build. It loads the sources with env-runner (virtual modules and host plugins for TypeScript, aliases, and similar), like the dev server does, but loads the runner once and never watches.

The problem is the proxy hop. Every runner starts its own srvx server on 127.0.0.1:0 (toServerOptions() in src/common/worker-utils.ts forces port, hostname, silent and gracefulShutdown), and RunnerManager.fetch() forwards each request to it over HTTP. That is fine in dev, but in production every request goes through two HTTP servers.

Either of these would remove the hop. They could also both be supported:

  1. Let the worker listen publicly. Add a runner option (e.g. listen: { port, hostname, tls? }) so the worker's srvx server binds the public address and handles requests directly. WebSocket upgrades would hit the worker's own crossws plugin directly. The host only supervises: readiness (address message), shutdown (shutdown → ipc.onClose → exit) and restart on crash. fetch() on the host could keep working for internal requests. This works on the node-worker, node-process, bun-process and deno-process runners.
  2. Support data.virtual and plugins in SelfEnvRunner. Register the same loader hooks in the host process (module.registerHooks on Node.js and Deno, Bun.plugin() on Bun), with plugin handlers called in-process instead of over a port or socket. The host's own srvx server then calls entry.fetch directly: one process, no hop. Today SelfEnvRunner closes with an error when either is set.

Option 1 keeps process isolation and needs fewer changes. Option 2 is the leanest for production. Once one of these lands, Nitro will add a production entry (close hooks, WebSocket, scheduled tasks) and let users pick the runner.

🤖 Generated with AI assistant

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions