Skip to content

Endpoints and routing

An endpoint is a tuple: (domain, service, port, tls_mode, protocol, path). One app can declare multiple endpoints, and several endpoints may share a domain. Each endpoint becomes one Caddy route. Caddy receives all inbound traffic on :80 and :443 and matches by Host header, plus the optional path and gRPC content-type matchers.

Endpoints are indexed labels on any service in the app. The reconciler reads simpledeploy.endpoints.N.* for N = 0, 1, 2, ...:

services:
web:
image: ghcr.io/example/web:1.4
ports: ["8080"]
labels:
simpledeploy.endpoints.0.domain: "app.example.com"
simpledeploy.endpoints.0.service: "web"
simpledeploy.endpoints.0.port: "8080"
simpledeploy.endpoints.0.tls: "auto"
simpledeploy.endpoints.1.domain: "admin.example.com"
simpledeploy.endpoints.1.service: "web"
simpledeploy.endpoints.1.port: "8080"
simpledeploy.endpoints.1.tls: "auto"

Two endpoints, both pointing at the same service, served on two different domains.

For each endpoint, /internal/proxy/route.go (resolveEndpointUpstream) picks where Caddy proxies to, in this order:

  1. If the target service publishes a host port matching endpoint.port, the upstream is localhost:<host_port>.
  2. Otherwise, the resolver looks up the service’s container IP on the simpledeploy-public network via the Docker API and uses <container_ip>:<port>. Every endpoint-bearing service is auto-attached to this network by the compose mutation step during deploy, so Caddy can reach it whether SimpleDeploy runs natively on Linux (bridge IPs are host-routable) or inside a container on the same network.
  3. As a last-ditch fallback when the Docker API lookup fails (daemon down, container not yet attached), the upstream is the Docker DNS name <service>:<port>. Only works when Caddy and the target share a network.

You do not need to publish a host port to make an endpoint reachable. Host ports still work and, when present, take precedence (step 1).

Set per endpoint via simpledeploy.endpoints.N.tls:

  • auto (default): Caddy obtains a Let’s Encrypt cert via ACME using the email from tls.email in your config.
  • local: Caddy uses its internal CA. Useful for dev/staging without public DNS.
  • custom: Caddy loads <app_dir>/certs/<domain>.crt and .key from disk.
  • off: HTTP only. Caddy’s automatic HTTPS is disabled globally when this is the proxy-wide mode.

The proxy-wide mode comes from your config (tls.mode). Per-endpoint TLS modes layer on top. See TLS guide for the full matrix.

Two optional labels refine an endpoint:

  • simpledeploy.endpoints.N.protocol: http (default), h2c or grpc. h2c and grpc proxy to the upstream over HTTP/2 cleartext with immediate flushing. grpc additionally only matches native gRPC requests (Content-Type: application/grpc*, gRPC-Web excluded).
  • simpledeploy.endpoints.N.path: a Caddy path matcher such as /ws*.
labels:
simpledeploy.endpoints.0.domain: "api.example.com"
simpledeploy.endpoints.0.port: "50051"
simpledeploy.endpoints.0.protocol: "grpc"
simpledeploy.endpoints.1.domain: "api.example.com"
simpledeploy.endpoints.1.port: "8000"
simpledeploy.endpoints.1.path: "/ws*"
simpledeploy.endpoints.2.domain: "api.example.com"
simpledeploy.endpoints.2.port: "8001"

Route order per domain is fixed: grpc endpoints, then path endpoints (longest path first), then the catch-all. Every route is terminal, so the first match wins. Endpoints whose matchers collide (same domain, same path, both or neither grpc), or that share a domain with different tls modes, are rejected at deploy time. For apps already on disk the reconciler only warns and keeps the first endpoint (by label index N).

Routes are built in /internal/proxy/proxy.go (buildConfig) and pushed via caddy.Load() after every reconcile. Each route gets a handler chain in this order:

  1. simpledeploy_ipaccess (allowlist match against simpledeploy.access.allow)
  2. simpledeploy_ratelimit (per-domain token bucket, configured via simpledeploy.ratelimit.*)
  3. simpledeploy_metrics (records request count, latency and status code for the app’s request stats, including the 502 visitors get when the app cannot be reached)
  4. headers (safe-default security headers, see below)
  5. timeouts (HTTP routes only: cuts uploads that stall for a minute)
  6. reverse_proxy to the resolved upstream

SimpleDeploy adds these headers to your app’s responses, but only when your app does not already send them. If your app sets its own value (for example X-Frame-Options: DENY), that value is kept.

Header Default value When
X-Content-Type-Options nosniff Always
X-Frame-Options SAMEORIGIN Always
Referrer-Policy strict-origin-when-cross-origin Always
Strict-Transport-Security max-age=31536000; includeSubDomains Endpoints whose tls is not off