Allow cross-origin requests from localhost in production environment

https://codeberg.org/silverpill/mitra/issues/5
This commit is contained in:
silverpill 2022-02-08 13:16:38 +00:00
parent 0a8fbdafba
commit a63da82b85

View file

@ -60,7 +60,11 @@ async fn main() -> std::io::Result<()> {
},
Environment::Production => {
let allowed_origin = config.instance_url();
Cors::default().allowed_origin(&allowed_origin)
Cors::default()
.allowed_origin(&allowed_origin)
.allowed_origin_fn(|origin, _req_head| {
origin.as_bytes().starts_with(b"http://localhost:")
})
.allow_any_method()
.allow_any_header()
},