File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
quickwit/quickwit-serve/src Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ use tokio_util::either::Either;
2929use tower:: ServiceBuilder ;
3030use tower_http:: compression:: CompressionLayer ;
3131use tower_http:: compression:: predicate:: { NotForContentType , Predicate , SizeAbove } ;
32- use tower_http:: cors:: CorsLayer ;
32+ use tower_http:: cors:: { AllowOrigin , CorsLayer } ;
3333use tracing:: { error, info} ;
3434use warp:: filters:: log:: Info ;
3535use warp:: hyper:: http:: HeaderValue ;
@@ -480,6 +480,25 @@ fn get_status_with_error(rejection: Rejection) -> Result<RestApiError, Rejection
480480}
481481
482482fn build_cors ( cors_origins : & [ String ] ) -> CorsLayer {
483+ let debug_mode = quickwit_common:: get_bool_from_env ( "QW_ENABLE_CORS_DEBUG" , false ) ;
484+ if debug_mode {
485+ info ! ( "CORS debug mode is enabled, localhost and 127.0.0.1 origins will be allowed" ) ;
486+ return CorsLayer :: new ( )
487+ . allow_methods ( [
488+ Method :: GET ,
489+ Method :: POST ,
490+ Method :: PUT ,
491+ Method :: PATCH ,
492+ Method :: DELETE ,
493+ ] )
494+ . allow_origin ( AllowOrigin :: predicate ( |origin, _parts| {
495+ [ b"https://localhost:" , b"https://127.0.0.1:" ]
496+ . iter ( )
497+ . any ( |prefix| origin. as_bytes ( ) . starts_with ( * prefix) )
498+ } ) )
499+ . allow_headers ( [ http:: header:: CONTENT_TYPE ] ) ;
500+ }
501+
483502 let mut cors = CorsLayer :: new ( ) . allow_methods ( [
484503 Method :: GET ,
485504 Method :: POST ,
You can’t perform that action at this time.
0 commit comments