Documentation
¶
Overview ¶
Package edge holds the L7 reverse proxy and TLS-cert plumbing that fronts CloudMock and any local dev services for the iPad / tailnet workflow.
Until 2026-05 this code lived in pkg/gateway alongside the AWS API gateway handler and the DNS server, which made "where do I look?" ambiguous — gateway was three concerns under one name. The DNS server moved to pkg/dns, the observability primitives moved to pkg/observability, and this package now owns just the reverse proxy + cert lifecycle.
pkg/gateway re-exports ProxyRoute, ProxyServer, BuildRoutes, EnsureCerts, CertPair, and friends as type aliases / wrapper functions so historical importers keep working.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StartProxy ¶
func StartProxy(routes []ProxyRoute, tlsCert *CertPair)
StartProxy starts the reverse proxy on HTTP and optionally HTTPS. It tries port 80 first, falling back to 8080 if unavailable. If tlsCertFile and tlsKeyFile are provided, it also starts HTTPS on 443 (fallback 8443).
func StartProxyWithOpts ¶
func StartProxyWithOpts(routes []ProxyRoute, tlsCert *CertPair, opts ProxyOpts)
StartProxyWithOpts starts the proxy with request logging.
Types ¶
type CertPair ¶
type CertPair struct {
Cert tls.Certificate
CACert string // path to CA cert file
}
CertPair holds a TLS certificate and CA cert path for trust instructions.
func EnsureCerts ¶
EnsureCerts loads existing certificates from ~/.cloudmock/certs/ or generates new self-signed ones if they are missing, expired, or have mismatched SANs. Returns a CertPair ready for use with a TLS listener.
type ProxyOpts ¶
type ProxyOpts struct {
RequestLog *observability.RequestLog
Stats *observability.RequestStats
Broadcaster observability.RequestBroadcaster
}
ProxyOpts configures the proxy server.
type ProxyRoute ¶
type ProxyRoute struct {
Host string // e.g. "bff.localhost" or "bff.localhost.example.com"
Path string // path prefix, e.g. "/bff/" — empty means match all
Backend string // e.g. "http://localhost:3202"
PreserveHost bool // if true, forward original Host header to backend
// Service is the logical service name attached to log entries when this
// route is matched. Empty falls back to a host-substring heuristic for
// backwards compatibility with hand-rolled route tables.
Service string
}
ProxyRoute defines a single routing rule for the reverse proxy.
func BuildRoutes ¶
func BuildRoutes(primaryDomain, cloudmockDomain string) []ProxyRoute
BuildRoutes generates the routing table dynamically from domain names and port config. Order matters — more specific paths must come first.
func BuildRoutesWithPorts ¶
func BuildRoutesWithPorts(primaryDomain, cloudmockDomain string, p ServicePorts) []ProxyRoute
BuildRoutesWithPorts generates routes using explicit port configuration.
type ProxyServer ¶
type ProxyServer struct {
// contains filtered or unexported fields
}
ProxyServer is a virtual-host reverse proxy that routes requests to backend services based on Host header and path prefix.
func NewProxyServer ¶
func NewProxyServer(routes []ProxyRoute) *ProxyServer
NewProxyServer creates a new reverse proxy server with the given routes.
func NewProxyServerWithOpts ¶
func NewProxyServerWithOpts(routes []ProxyRoute, opts ProxyOpts) *ProxyServer
NewProxyServerWithOpts creates a proxy server with logging and broadcasting.
func (*ProxyServer) ServeHTTP ¶
func (ps *ProxyServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
type ServicePorts ¶
type ServicePorts struct {
Gateway int // cloudmock AWS API (default 4566)
Dashboard int // cloudmock dashboard (default 4500)
Admin int // admin API (default 4599)
App int // Expo/Metro app (default 8081)
BFF int // BFF service (default 3202)
GraphQL int // GraphQL server (default 4000)
}
ServicePorts maps logical service names to their listen ports. These are read from cloudmock config and environment variables.
func DefaultServicePorts ¶
func DefaultServicePorts() ServicePorts
DefaultServicePorts returns ports from environment or sensible defaults.