Skip to content

Commit e64ceb1

Browse files
committed
refactor: use validate request for network
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 2f1adce commit e64ceb1

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

crates/service/src/service/indexer_service.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,21 @@ impl IndexerService {
405405
.layer(misc_rate_limiter);
406406

407407
if options.config.service.serve_network_subgraph {
408-
info!("Serving network subgraph at /network");
408+
if let Some(free_auth_token) = &options.config.service.serve_auth_token {
409+
info!("Serving network subgraph at /network");
409410

410-
misc_routes = misc_routes.route(
411-
"/network",
412-
post(static_subgraph_request_handler)
413-
.route_layer(Extension(network_subgraph))
414-
.route_layer(static_subgraph_rate_limiter.clone()),
415-
);
411+
let auth_layer = ValidateRequestHeaderLayer::bearer(free_auth_token);
412+
413+
misc_routes = misc_routes.route(
414+
"/network",
415+
post(static_subgraph_request_handler)
416+
.route_layer(auth_layer)
417+
.route_layer(Extension(network_subgraph))
418+
.route_layer(static_subgraph_rate_limiter.clone()),
419+
);
420+
} else {
421+
warn!("`serve_network_subgraph` is enabled but no `serve_auth_token` provided. Disabling it.");
422+
}
416423
}
417424

418425
if options.config.service.serve_escrow_subgraph {
@@ -424,9 +431,10 @@ impl IndexerService {
424431
misc_routes = misc_routes
425432
.route(
426433
"/escrow",
427-
post(static_subgraph_request_handler).route_layer(auth_layer),
434+
post(static_subgraph_request_handler)
435+
.route_layer(auth_layer)
436+
.route_layer(Extension(escrow_subgraph)),
428437
)
429-
.route_layer(Extension(escrow_subgraph))
430438
.route_layer(static_subgraph_rate_limiter);
431439
} else {
432440
warn!("`serve_escrow_subgraph` is enabled but no `serve_auth_token` provided. Disabling it.");

0 commit comments

Comments
 (0)