Skip to main content

Core Types

RouteInfo

Represents a mapping from a hostname to a local port. Used by the proxy server to route incoming requests.
string
The hostname to match against the Host header (e.g., “api.localhost”, “app.myproject.localhost”)
number
The local port number where the application is listening (e.g., 3000, 4000)
Example:

RouteMapping

Extends RouteInfo with process tracking. Used internally by RouteStore to manage route ownership and lifecycle.
number
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.
Example:

ProxyServerOptions

Configuration options for createProxyServer().
() => RouteInfo[]
required
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.
number
required
The port number the proxy server is listening on. Used to construct correct URLs in error pages and route listings.
(message: string) => void
Optional error logger called when proxy errors occur. Defaults to console.error if not provided.
TLSOptions
Optional TLS configuration. When provided, enables HTTP/2 over TLS with HTTP/1.1 fallback.
Example:

ProxyServer

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:

Error Types

RouteConflictError

Thrown by RouteStore.addRoute() when attempting to register a hostname that’s already in use by a live process (unless force: true is specified).
string
The hostname that caused the conflict
number
Process ID of the process that currently owns the hostname
Example:

Constants

PORTLESS_HEADER

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:

File Permissions

File and directory permission modes used by RouteStore.

Import Examples

CommonJS

Type Guards

isValidRoute (Internal)

While not exported, here’s how RouteStore validates route data:
You can implement similar validation in your code:

API Overview

Getting started with the programmatic API

createProxyServer

Create proxy servers

RouteStore

Manage route mappings