Skip to content

Routing Rules Reference

Routes belong to listeners and are evaluated only for traffic received by that listener.

Route Fields And Defaults

A non-default route requires at least one of:

  • host pattern,
  • path prefix.
FieldRule
listener_idRequired. Route is scoped to this listener.
priorityLower numbers evaluate first.
host_patternExact host or wildcard subdomain.
path_prefixMust start with / when set.
actionforward or redirect; defaults to forward when unspecified.
target_load_balancingDefaults to round-robin for forward target pools.
is_defaultMarks the listener default route. One default route is allowed per listener.
redirect_status_codeDefaults to 302 when unset.
redirect_preserve_path_suffixDefaults enabled.
redirect_preserve_queryDefaults enabled.

Target Fields

Forward routes require at least one enabled target.

FieldRule
target_typeproxy or static.
urlRequired for proxy targets. Must be an HTTP or HTTPS origin.
transportdirect or agent for proxy targets.
agent_selector.match_labelsRequired for agent targets. All labels must match the same enabled agent.
priority_groupLowest available group is selected; higher groups are failover.
weight1 to 1000000; defaults to 100.
agent_load_balancingAgent selection policy for agent targets.
upstream_response_header_timeout_millisDefaults to 60000.

Static targets use static_status_code, static_response_headers, and either inline body text or a generic response template.

Agent labels are configured in the Agent editor. Labels under p2pstream.io/ are system-owned. Use p2pstream.io/agent-id=<agent public ID> for exact-agent targeting. Empty selector values are allowed and match only agents with the same empty label value.

Validation Rules

PatternMatches
app.example.comexactly app.example.com
*.example.comapp.example.com, media.example.com

Wildcard patterns do not match the apex example.com.

Redirect routes require target mode, target, and status code 301, 302, 307, or 308.

p2pstream route editor showing listener, host pattern, path prefix, action, targets, and priority
The route editor defines the listener-scoped match, action, priority, and forward target pool or redirect settings.
p2pstream route editor showing a direct upstream target
Direct proxy targets are used when the p2pstream server itself can reach the upstream origin.
p2pstream route editor showing an agent-selected proxy target
Agent proxy targets select a connected agent by labels and dial the origin from that agent's network.
p2pstream route editor showing redirect action settings
Redirect routes return a local redirect response without selecting a route target.
p2pstream route target editor showing a static response target
Static response targets return a local status, headers, and body from p2pstream without forwarding upstream.

Runtime Effects

Routes are sorted by priority ascending, then route ID ascending. If no enabled non-default route matches, the listener default route handles the request.

At request time, disabled targets, unhealthy targets, invalid target configs, and unavailable agent selector matches are skipped. p2pstream selects from the lowest available priority group. If no target is usable, the response is 503.

When target health checks are enabled, connection and timeout failures mark the selected target or target-agent path temporarily unhealthy for later requests. The original request is not replayed to another target.

After a route and target are selected, cache rules may serve eligible proxy GET or HEAD requests. Redirect routes and static targets are not cached.

Example

Specific route before broad fallback:

PriorityHostPathTarget
10app.example.com/apiapi-direct
20app.example.com/app-agent
defaultempty/welcome-static

Operations documentation for self-hosted p2pstream deployments.