fix: add access-control-allow-origin to static assets

This commit is contained in:
Ruben Fiszel
2023-12-05 12:15:21 +01:00
parent 0ac99e57da
commit fde056a62f
+3 -1
View File
@@ -47,7 +47,9 @@ fn serve_path(path: &str) -> Response<BoxBody> {
Some(content) => {
let body = body::boxed(body::Full::from(content.data));
let mime = mime_guess::from_path(path).first_or_octet_stream();
let mut res = Response::builder().header(header::CONTENT_TYPE, mime.as_ref());
let mut res = Response::builder()
.header(header::CONTENT_TYPE, mime.as_ref())
.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*");
if mime.as_ref() == mime::APPLICATION_JAVASCRIPT {
res = res.header(header::CACHE_CONTROL, "max-age=31536000");
} else if (mime.type_(), mime.subtype()) == (mime::TEXT, mime::CSS) {