@@ -10,14 +10,15 @@ use alloy_sol_types::eip712_domain;
10
10
use anyhow;
11
11
use autometrics:: prometheus_exporter;
12
12
use axum:: extract:: MatchedPath ;
13
+ use axum:: extract:: Request as ExtractRequest ;
13
14
use axum:: http:: { Method , Request } ;
14
- use axum:: serve;
15
15
use axum:: {
16
16
async_trait,
17
17
response:: { IntoResponse , Response } ,
18
18
routing:: { get, post} ,
19
19
Extension , Json , Router ,
20
20
} ;
21
+ use axum:: { serve, ServiceExt } ;
21
22
use build_info:: BuildInfo ;
22
23
use eventuals:: Eventual ;
23
24
use reqwest:: StatusCode ;
@@ -30,9 +31,7 @@ use thiserror::Error;
30
31
use tokio:: net:: TcpListener ;
31
32
use tokio:: signal;
32
33
use tower_governor:: { governor:: GovernorConfigBuilder , GovernorLayer } ;
33
- use tower_http:: cors;
34
- use tower_http:: cors:: CorsLayer ;
35
- use tower_http:: trace:: TraceLayer ;
34
+ use tower_http:: { cors, cors:: CorsLayer , normalize_path:: NormalizePath , trace:: TraceLayer } ;
36
35
use tracing:: { info, info_span} ;
37
36
38
37
use crate :: {
@@ -385,40 +384,42 @@ impl IndexerService {
385
384
)
386
385
. with_state ( state. clone ( ) ) ;
387
386
388
- let router = misc_routes
389
- . merge ( data_routes)
390
- . merge ( options. extra_routes )
391
- . layer (
392
- CorsLayer :: new ( )
393
- . allow_origin ( cors:: Any )
394
- . allow_headers ( cors:: Any )
395
- . allow_methods ( [ Method :: OPTIONS , Method :: POST , Method :: GET ] ) ,
396
- )
397
- . layer (
398
- TraceLayer :: new_for_http ( )
399
- . make_span_with ( |req : & Request < _ > | {
400
- let method = req. method ( ) ;
401
- let uri = req. uri ( ) ;
402
- let matched_path = req
403
- . extensions ( )
404
- . get :: < MatchedPath > ( )
405
- . map ( MatchedPath :: as_str) ;
406
-
407
- info_span ! (
408
- "http_request" ,
409
- %method,
410
- %uri,
411
- matched_path,
412
- )
413
- } )
414
- // we disable failures here because we doing our own error logging
415
- . on_failure (
416
- |_error : tower_http:: classify:: ServerErrorsFailureClass ,
417
- _latency : Duration ,
418
- _span : & tracing:: Span | { } ,
419
- ) ,
420
- )
421
- . with_state ( state) ;
387
+ let router = NormalizePath :: trim_trailing_slash (
388
+ misc_routes
389
+ . merge ( data_routes)
390
+ . merge ( options. extra_routes )
391
+ . layer (
392
+ CorsLayer :: new ( )
393
+ . allow_origin ( cors:: Any )
394
+ . allow_headers ( cors:: Any )
395
+ . allow_methods ( [ Method :: OPTIONS , Method :: POST , Method :: GET ] ) ,
396
+ )
397
+ . layer (
398
+ TraceLayer :: new_for_http ( )
399
+ . make_span_with ( |req : & Request < _ > | {
400
+ let method = req. method ( ) ;
401
+ let uri = req. uri ( ) ;
402
+ let matched_path = req
403
+ . extensions ( )
404
+ . get :: < MatchedPath > ( )
405
+ . map ( MatchedPath :: as_str) ;
406
+
407
+ info_span ! (
408
+ "http_request" ,
409
+ %method,
410
+ %uri,
411
+ matched_path,
412
+ )
413
+ } )
414
+ // we disable failures here because we doing our own error logging
415
+ . on_failure (
416
+ |_error : tower_http:: classify:: ServerErrorsFailureClass ,
417
+ _latency : Duration ,
418
+ _span : & tracing:: Span | { } ,
419
+ ) ,
420
+ )
421
+ . with_state ( state) ,
422
+ ) ;
422
423
423
424
Self :: serve_metrics ( options. config . server . metrics_host_and_port ) ;
424
425
@@ -432,7 +433,7 @@ impl IndexerService {
432
433
433
434
Ok ( serve (
434
435
listener,
435
- router . into_make_service_with_connect_info :: < SocketAddr > ( ) ,
436
+ ServiceExt :: < ExtractRequest > :: into_make_service_with_connect_info :: < SocketAddr > ( router ) ,
436
437
)
437
438
. with_graceful_shutdown ( shutdown_signal ( ) )
438
439
. await ?)
0 commit comments