Edge Region Auto-Routing
Status: Implemented
Overview
When multiple edge regions are configured, the CLI automatically probes each one and connects to the lowest-latency edge. This reduces round-trip time for tunnelled requests without requiring the user to manually pick a region.
Components
Bridge API
GET /api/cli/edge-regions(public, no auth) -- returns the list of active edge regions with WebSocket URLs.- Controller:
App\Http\Controllers\Api\CliEdgeRegionsController - Reads from
config('jetty.network_regions')and builds per-region WebSocket URLs using each region'shostname(falls back to the defaultedge_ws_urlwhen no hostname is set).
Response shape:
{
"edges": [
{"url": "wss://us.tunnels.example.com/agent", "region": "us-east", "location": "New York"},
{"url": "wss://eu.tunnels.example.com/agent", "region": "eu-west", "location": "Amsterdam"}
]
}
CLI ApiClient (jetty-client/src/ApiClient.php)
getEdgeRegions(): array-- callsGET /api/cli/edge-regionsand returns theedgesarray. Returns[]on any failure.selectFastestEdge(array $edges): ?array-- sends a HEAD request to each edge (convertingwss://tohttps://for the probe), measures wall-clock latency, and returns the fastest entry with an addedlatency_mskey.
CLI ShareCommand (jetty-client/src/Commands/ShareCommand.php)
Before connecting to the edge WebSocket the command:
- Calls
getEdgeRegions(). - If more than one edge is returned, runs
selectFastestEdge(). - Overrides the default
$wsURL with the winning edge URL. - Displays the selected region:
Connecting to New York (42ms)... - Falls back to the default edge URL from the tunnel API response if probing fails or only one region exists.
The selected $ws URL is used for both the initial connection and for
reconnects via EdgeAgent::run().
Configuration
Operators configure regions via the JETTY_NETWORK_REGIONS environment
variable (JSON array). Each region object should include:
| Field | Required | Description |
|---|---|---|
code |
no | Short identifier, e.g. us-east |
name |
yes* | Human-readable name |
location |
yes* | City / geographic label |
hostname |
no | Dedicated edge hostname for this region |
status |
no | active (default) or inactive |
*At least one of name or location must be non-empty.
When no regions are configured (single-edge deployments), the endpoint
returns a single entry with the default edge_ws_url and the CLI skips
probing entirely.
Send feedback
Found an issue or have a suggestion? Let us know.