Process ID of the application that registered this route. Use process.pid for the current process, or 0 for system-managed routes that should never be automatically cleaned up.
Callback function invoked on every request to retrieve the current route table. This enables dynamic routing where routes can be added/removed without restarting the server.
Return type of createProxyServer(). When TLS is disabled, returns an http.Server. When TLS is enabled, returns a net.Server that wraps both HTTP/2 and HTTP/1.1 servers.Example:
import type { ProxyServer } from "portless";let server: ProxyServer;if (useTLS) { server = createProxyServer({ ...options, tls: tlsConfig });} else { server = createProxyServer(options);}server.listen(8080);
Process ID of the process that currently owns the hostname
Example:
import { RouteStore, RouteConflictError } from "portless";const store = new RouteStore("/tmp/portless");try { store.addRoute("api.localhost", 3000, process.pid);} catch (err) { if (err instanceof RouteConflictError) { console.error( `Cannot register ${err.hostname}: already owned by PID ${err.existingPid}` ); // Option 1: Wait for the other process to exit // Option 2: Use force flag to override store.addRoute(err.hostname, 3000, process.pid, true); } else { throw err; }}
HTTP response header added to all proxied responses. Used to identify that a response came through a Portless proxy (useful for health checks and debugging).Example:
fetch("http://api.localhost:8080/health") .then(res => { if (res.headers.get("X-Portless")) { console.log("Request went through Portless proxy"); } });
While not exported, here’s how RouteStore validates route data:
function isValidRoute(value: unknown): value is RouteMapping { return ( typeof value === "object" && value !== null && typeof (value as RouteMapping).hostname === "string" && typeof (value as RouteMapping).port === "number" && typeof (value as RouteMapping).pid === "number" );}
You can implement similar validation in your code:
function validateRouteInfo(data: unknown): RouteInfo { if ( typeof data !== "object" || data === null || typeof (data as RouteInfo).hostname !== "string" || typeof (data as RouteInfo).port !== "number" ) { throw new TypeError("Invalid RouteInfo object"); } return data as RouteInfo;}