Add http_cors_allowlist configuration option
This commit is contained in:
parent
6fc319f7dd
commit
75fa39718c
2 changed files with 9 additions and 3 deletions
|
@ -103,6 +103,9 @@ pub struct Config {
|
|||
pub http_host: String,
|
||||
pub http_port: u32,
|
||||
|
||||
#[serde(default)]
|
||||
pub http_cors_allowlist: Vec<String>,
|
||||
|
||||
#[serde(default = "default_log_level")]
|
||||
pub log_level: LogLevel,
|
||||
|
||||
|
|
|
@ -59,9 +59,12 @@ async fn main() -> std::io::Result<()> {
|
|||
Cors::permissive()
|
||||
},
|
||||
Environment::Production => {
|
||||
let allowed_origin = config.instance_url();
|
||||
Cors::default()
|
||||
.allowed_origin(&allowed_origin)
|
||||
let mut cors_config = Cors::default();
|
||||
for origin in config.http_cors_allowlist.iter() {
|
||||
cors_config = cors_config.allowed_origin(&origin);
|
||||
};
|
||||
cors_config
|
||||
.allowed_origin(&config.instance_url())
|
||||
.allowed_origin_fn(|origin, _req_head| {
|
||||
origin.as_bytes().starts_with(b"http://localhost:")
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue