File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ serde_json = "1.0"
1111tempfile = " 3.12"
1212thiserror = " 1.0"
1313tokio = { version = " 1.39" , features = [" macros" , " rt-multi-thread" ] }
14- tower-http = { version = " 0.5" , features = [" trace" ] }
14+ tower-http = { version = " 0.5" , features = [" trace" , " cors " ] }
1515tracing = " 0.1"
1616tracing-subscriber = { version = " 0.3" , features = [" env-filter" ] }
1717uuid = { version = " 1.8" , features = [" v4" ] }
Original file line number Diff line number Diff line change @@ -2,12 +2,23 @@ use crate::app::ScanService;
22use crate :: infra:: http:: handlers:: { health, scan_bundle} ;
33use axum:: routing:: { get, post} ;
44use axum:: Router ;
5+ use axum:: http:: { HeaderValue , Method } ;
6+ use tower_http:: cors:: { Any , CorsLayer } ;
57use tower_http:: trace:: TraceLayer ;
68
79pub fn build_router ( scan_service : ScanService ) -> Router {
10+ let cors = CorsLayer :: new ( )
11+ . allow_origin ( [
12+ HeaderValue :: from_static ( "http://localhost:3000" ) ,
13+ HeaderValue :: from_static ( "http://127.0.0.1:3000" ) ,
14+ ] )
15+ . allow_methods ( [ Method :: GET , Method :: POST ] )
16+ . allow_headers ( Any ) ;
17+
818 Router :: new ( )
919 . route ( "/healthz" , get ( health) )
1020 . route ( "/api/v1/scan" , post ( scan_bundle) )
1121 . with_state ( scan_service)
22+ . layer ( cors)
1223 . layer ( TraceLayer :: new_for_http ( ) )
1324}
You can’t perform that action at this time.
0 commit comments