Skip to main content

Module dev_proxy

Module dev_proxy 

Source
Expand description

Native reverse proxy for container-agent dev servers.

Routes http://<project>-<agent_id>.localhost:{DEV_PROXY_PORT}/... to whatever internal ip:port that agent’s dev server registered via the RegisterDevServer MCP tool (the HTTP endpoint backing that tool lives in crates/srv/src/server/app_api/dev_server.rs; this module owns the routing table and the proxy server itself). See docs/specs/SPEC_NATIVE_CONTAINER_DEV_PROXY_2026_09_19.md.

Deliberately NOT a general-purpose reverse proxy (spec §4): Host-header → backend address is the entire feature. No path routing, no TLS, no auth, no rate limiting. WebSocket upgrades are passed through (a dev server’s hot reload needs one), and a container whose address the host cannot reach (Docker Desktop) is reached through the relay in dev_relay.

Modules§

forward
One request through the dev proxy to a connection already open to the dev server, WebSocket upgrades included (Vite’s hot reload is one).

Structs§

DevProxyRegistry
"<project>-<agent_id>" → the container’s internal ip:port its dev server is actually listening on. Cleared per-agent when that agent’s container stops (ContainerManager::stop/remove in container.rs call unregister_container — see that module’s cleanup_dev_proxy_routes).

Enums§

Target
How to reach a registered dev server.

Constants§

DEV_PROXY_PORT
The local port the proxy tries first. Nothing else in agentmux-srv binds it (checked: no other TcpListener::bind or config default references 8090 anywhere in this crate). See spec §5. A second instance on the same host finds it held and takes a free port instead; port says which one this instance got.

Functions§

port
The port this instance’s proxy listens on: the one it bound, which is DEV_PROXY_PORT unless another instance on the host held it. Before the proxy has bound, the preferred port is the best answer there is.
router
Builds the proxy’s axum router. Split out from serve so tests can drive it directly (via a real bound listener) without needing the fixed DEV_PROXY_PORT to be free.
routing_key_from_host
Host header → routing key. "pulse-korp.localhost:8090" and "pulse-korp.localhost" both become "pulse-korp". A Host that isn’t .localhost is still accepted (minus port, lowercased) rather than rejected outright — an empty/missing Host is the only thing that produces None. Whether the key actually resolves to anything is the registry lookup’s job, not this function’s; either way the caller gets a clear “no dev server registered for <key>” 404, never a confusing hostname-format error.
serve
Binds DEV_PROXY_PORT on loopback (or a free port when another instance holds it) and serves the proxy until the process exits. Spawned once at srv startup (main.rs). A bind failure is logged and the proxy is simply unavailable for this run — never fatal to srv startup; dev-server routing is an additive convenience, not core functionality.