Time-Based Routing
Status: Implemented
Overview
Time-based routing allows tunnel owners to route traffic to different local upstreams depending on the current time of day, timezone, and day of week. This is useful for scenarios like routing to a maintenance page outside business hours, or directing traffic to different backends on weekends.
Design
Match Type
A new match_type value time_range is added to the existing routing rule
system alongside path_prefix, header, and weighted.
Rule Fields
Time-range rules add four fields to RoutingRule:
| Field | Type | Description |
|---|---|---|
time_start |
string |
Start time in HH:MM 24-hour format |
time_end |
string |
End time in HH:MM 24-hour format |
timezone |
string |
IANA timezone identifier (e.g. "America/New_York") |
days |
[]int |
Days of week: 0=Sun, 1=Mon, ... 6=Sat (optional) |
Matching Logic
- The current time is converted to the rule's timezone.
- If
daysis non-empty, the current weekday must be in the list. - The current HH:MM is checked against the
time_start-time_endrange. - Midnight wraparound is supported: if
time_start > time_end(e.g. 22:00-06:00), the rule matches when the current time is >= start OR < end. - The range is inclusive of start and exclusive of end.
Evaluation Order
Time-range rules participate in the standard first-match-wins ordering. They are evaluated in the same priority pass as path_prefix and header rules.
Components Modified
- wsproto (
cli/internal/wsproto/proto.go): AddedTimeStart,TimeEnd,Timezone, andDaysfields toRoutingRule. - Edge routing (
cli/internal/edge/edge.go): Addedtime_rangecase inmatchRoutingRuleandmatchesTimeRangehelper function. - Validator (
app/Support/TunnelRoutingRulesValidator.php): Added validation for HH:MM format, valid IANA timezone, and days 0-6. - Livewire component (
app/Livewire/Tunnels/ManageRoutingRules.php): Added time_range fields to load/add/save andtoggleDaymethod. - Blade UI (
resources/views/livewire/tunnels/manage-routing-rules.blade.php): Added time_range option with start/end time inputs, timezone input, and day checkboxes.
Send feedback
Found an issue or have a suggestion? Let us know.