Documentation for Jetty

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

  1. The current time is converted to the rule's timezone.
  2. If days is non-empty, the current weekday must be in the list.
  3. The current HH:MM is checked against the time_start-time_end range.
  4. 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.
  5. 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): Added TimeStart, TimeEnd, Timezone, and Days fields to RoutingRule.
  • Edge routing (cli/internal/edge/edge.go): Added time_range case in matchRoutingRule and matchesTimeRange helper 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 and toggleDay method.
  • 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.