@@ -36,7 +36,9 @@ use tokio::net::TcpListener;
3636use tokio:: signal;
3737use tokio:: sync:: watch:: Receiver ;
3838use tower_governor:: { governor:: GovernorConfigBuilder , GovernorLayer } ;
39+ use tower_http:: validate_request:: ValidateRequestHeaderLayer ;
3940use tower_http:: { cors, cors:: CorsLayer , normalize_path:: NormalizePath , trace:: TraceLayer } ;
41+ use tracing:: warn;
4042use tracing:: { error, info, info_span} ;
4143
4244use crate :: routes:: health;
@@ -414,12 +416,21 @@ impl IndexerService {
414416 }
415417
416418 if options. config . service . serve_escrow_subgraph {
417- info ! ( "Serving escrow subgraph at /escrow" ) ;
418-
419- misc_routes = misc_routes
420- . route ( "/escrow" , post ( static_subgraph_request_handler) )
421- . route_layer ( Extension ( escrow_subgraph) )
422- . route_layer ( static_subgraph_rate_limiter) ;
419+ if let Some ( free_auth_token) = & options. config . service . serve_auth_token {
420+ info ! ( "Serving escrow subgraph at /escrow" ) ;
421+
422+ let auth_layer = ValidateRequestHeaderLayer :: bearer ( free_auth_token) ;
423+
424+ misc_routes = misc_routes
425+ . route (
426+ "/escrow" ,
427+ post ( static_subgraph_request_handler) . route_layer ( auth_layer) ,
428+ )
429+ . route_layer ( Extension ( escrow_subgraph) )
430+ . route_layer ( static_subgraph_rate_limiter) ;
431+ } else {
432+ warn ! ( "`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it." ) ;
433+ }
423434 }
424435
425436 misc_routes = misc_routes. with_state ( state. clone ( ) ) ;
0 commit comments