Skip to content

Commit a498604

Browse files
configure CORS with env var (#846)
set P_CORS to false to allow on origin mismatch default is set to true to block on origin mismatch Fixes: #697
1 parent c4731e6 commit a498604

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

server/src/cli.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ pub struct Cli {
9898

9999
/// Size for local cache
100100
pub query_cache_size: u64,
101+
102+
/// CORS behaviour
103+
pub cors: bool,
101104
}
102105

103106
impl Cli {
@@ -130,6 +133,7 @@ impl Cli {
130133
pub const DEFAULT_USERNAME: &'static str = "admin";
131134
pub const DEFAULT_PASSWORD: &'static str = "admin";
132135
pub const FLIGHT_PORT: &'static str = "flight-port";
136+
pub const CORS: &'static str = "cors";
133137

134138
pub fn local_stream_data_path(&self, stream_name: &str) -> PathBuf {
135139
self.local_staging_path.join(stream_name)
@@ -316,6 +320,16 @@ impl Cli {
316320
.value_parser(value_parser!(u16))
317321
.help("Port for Arrow Flight Querying Engine"),
318322
)
323+
.arg(
324+
Arg::new(Self::CORS)
325+
.long(Self::CORS)
326+
.env("P_CORS")
327+
.value_name("BOOL")
328+
.required(false)
329+
.default_value("true")
330+
.value_parser(value_parser!(bool))
331+
.help("Enable/Disable CORS, default disabled"),
332+
)
319333
.arg(
320334
Arg::new(Self::LIVETAIL_CAPACITY)
321335
.long(Self::LIVETAIL_CAPACITY)
@@ -451,6 +465,10 @@ impl FromArgMatches for Cli {
451465
.get_one::<u16>(Self::FLIGHT_PORT)
452466
.cloned()
453467
.expect("default for flight port");
468+
self.cors = m
469+
.get_one::<bool>(Self::CORS)
470+
.cloned()
471+
.expect("default for CORS");
454472
self.livetail_channel_capacity = m
455473
.get_one::<usize>(Self::LIVETAIL_CAPACITY)
456474
.cloned()

server/src/handlers/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn metrics_path() -> String {
5454
}
5555

5656
pub(crate) fn cross_origin_config() -> Cors {
57-
if cfg!(feature = "debug") {
57+
if !CONFIG.parseable.cors || cfg!(feature = "debug") {
5858
Cors::permissive().block_on_origin_mismatch(false)
5959
} else {
6060
Cors::default().block_on_origin_mismatch(false)

0 commit comments

Comments
 (0)