Configuration for the route pair
Backend service host
Backend service port
Host pattern to match
MITMproxy host
OptionalmitmproxyPort?: numberMITMproxy proxy port (default: 8080)
Optionalpriority?: numberRoute priority (optional)
Route ID (used for both routes)
Object with direct and proxied route configurations
Direct route (Client → Caddy → Backend)
Proxied route (Client → Caddy → MITMproxy → Backend)
const routes = buildMitmproxyRoutePair({
host: "api.example.com",
backendHost: "backend-service",
backendPort: 3000,
mitmproxyHost: "mitmproxy",
routeId: "api_route",
});
// Start with direct routing
await client.addRoute("https_server", routes.direct, routes.direct["@id"]);
// Hot-swap to enable interception (no downtime)
await client.removeRouteById("https_server", routes.direct["@id"]);
await client.addRoute("https_server", routes.proxied, routes.proxied["@id"]);
// Hot-swap back to direct (disable interception)
await client.removeRouteById("https_server", routes.proxied["@id"]);
await client.addRoute("https_server", routes.direct, routes.direct["@id"]);
Create a hot-swappable route pair for enabling/disabling MITMproxy interception
Returns both a direct route and a MITMproxy-intercepted route with the same ID. Use this to easily toggle between direct and intercepted traffic at runtime.