Skip to content

Conversation

@Abdul-Andha
Copy link
Contributor

Description

When QW_ENABLE_CORS_DEBUG=true, the origins localhost:* and 127.0.0.1:* will be allowed

How was this PR tested?

  • Tested locally and make test-all

@Abdul-Andha Abdul-Andha requested a review from guilload October 28, 2025 20:04
}

fn build_cors(cors_origins: &[String]) -> CorsLayer {
let debug_mode = quickwit_common::get_bool_from_env("QW_ENABLE_DEBUG_CORS", false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let debug_mode = quickwit_common::get_bool_from_env("QW_ENABLE_DEBUG_CORS", false);
let debug_mode = quickwit_common::get_bool_from_env("QW_ENABLE_CORS_DEBUG", false);

fn build_cors(cors_origins: &[String]) -> CorsLayer {
let debug_mode = quickwit_common::get_bool_from_env("QW_ENABLE_DEBUG_CORS", false);
if debug_mode {
info!("DEBUG CORS is enabled, localhost and 127.0.0.1 origins will be allowed");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
info!("DEBUG CORS is enabled, localhost and 127.0.0.1 origins will be allowed");
info!("CORS debug mode is enabled, localhost and 127.0.0.1 origins will be allowed");

if debug_mode {
info!("DEBUG CORS is enabled, localhost and 127.0.0.1 origins will be allowed");
return CorsLayer::new()
.allow_methods([Method::GET])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a feeling you will need more methods eventually: wanna add POST, PUT, PATCH, DELETE?

return CorsLayer::new()
.allow_methods([Method::GET])
.allow_origin(AllowOrigin::predicate(|origin, _parts| {
origin.as_bytes().starts_with(b"https://localhost:")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: easier to extend in the future

Suggested change
origin.as_bytes().starts_with(b"https://localhost:")
[b"https://localhost:", b"https://127.0.0.1:"]
.iter()
.any(|prefix| origin.as_bytes().starts_with(*prefix))

@Abdul-Andha Abdul-Andha merged commit e71f49e into main Oct 28, 2025
8 checks passed
@Abdul-Andha Abdul-Andha deleted the abdul.andha/cors-debug-mode branch October 28, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants