@@ -6,7 +6,7 @@ use std::sync::Arc;
66use super :: { SEC_WEBSOCKET_PROTOCOL , X_RIVET_TOKEN } ;
77pub ( crate ) const WS_PROTOCOL_TOKEN : & str = "rivet_token." ;
88
9- /// Route requests to the API service
9+ /// Route requests to the runner service using header-based routing
1010#[ tracing:: instrument( skip_all) ]
1111pub async fn route_request (
1212 ctx : & StandaloneCtx ,
@@ -19,8 +19,38 @@ pub async fn route_request(
1919 return Ok ( None ) ;
2020 }
2121
22- tracing:: debug!( ?host, path, "routing to runner" ) ;
22+ tracing:: debug!( ?host, path, "routing to runner via header " ) ;
2323
24+ route_runner_internal ( ctx, host, headers) . await . map ( Some )
25+ }
26+
27+ /// Route requests to the runner service using path-based routing
28+ /// Matches path: /runners/connect
29+ #[ tracing:: instrument( skip_all) ]
30+ pub async fn route_request_path_based (
31+ ctx : & StandaloneCtx ,
32+ host : & str ,
33+ path : & str ,
34+ headers : & hyper:: HeaderMap ,
35+ ) -> Result < Option < RoutingOutput > > {
36+ // Check if path matches /runners/connect
37+ let path_without_query = path. split ( '?' ) . next ( ) . unwrap_or ( path) ;
38+ if path_without_query != "/runners/connect" {
39+ return Ok ( None ) ;
40+ }
41+
42+ tracing:: debug!( ?host, path, "routing to runner via path" ) ;
43+
44+ route_runner_internal ( ctx, host, headers) . await . map ( Some )
45+ }
46+
47+ /// Internal runner routing logic shared by both header-based and path-based routing
48+ #[ tracing:: instrument( skip_all) ]
49+ async fn route_runner_internal (
50+ ctx : & StandaloneCtx ,
51+ host : & str ,
52+ headers : & hyper:: HeaderMap ,
53+ ) -> Result < RoutingOutput > {
2454 // Validate that the host is valid for the current datacenter
2555 let current_dc = ctx. config ( ) . topology ( ) . current_dc ( ) ?;
2656 if !current_dc. is_valid_regional_host ( host) {
@@ -95,5 +125,5 @@ pub async fn route_request(
95125 }
96126
97127 let tunnel = pegboard_runner:: PegboardRunnerWsCustomServe :: new ( ctx. clone ( ) ) ;
98- Ok ( Some ( RoutingOutput :: CustomServe ( Arc :: new ( tunnel) ) ) )
128+ Ok ( RoutingOutput :: CustomServe ( Arc :: new ( tunnel) ) )
99129}
0 commit comments