mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-07 08:02:40 +00:00
do not cache html, cache everything else for a long time
This commit is contained in:
@@ -12,6 +12,7 @@ use axum::{
|
||||
response::IntoResponse,
|
||||
};
|
||||
|
||||
use mime_guess::mime;
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
// static_handler is a handler that serves static files from the
|
||||
@@ -46,11 +47,17 @@ fn serve_path(path: String) -> Response<BoxBody> {
|
||||
Some(content) => {
|
||||
let body = body::boxed(body::Full::from(content.data));
|
||||
let mime = mime_guess::from_path(path).first_or_octet_stream();
|
||||
Response::builder()
|
||||
.header(header::CONTENT_TYPE, mime.as_ref())
|
||||
.header(header::CACHE_CONTROL, "max-age=3600".to_owned())
|
||||
.body(body)
|
||||
.unwrap()
|
||||
let mut res = Response::builder().header(header::CONTENT_TYPE, mime.as_ref());
|
||||
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) {
|
||||
res = res.header(header::CACHE_CONTROL, "max-age=31536000");
|
||||
} else if (mime.type_()) == (mime::IMAGE) {
|
||||
res = res.header(header::CACHE_CONTROL, "max-age=31536000");
|
||||
} else {
|
||||
res = res.header(header::CACHE_CONTROL, "no-cache, no-store, must-revalidate");
|
||||
}
|
||||
res.body(body).unwrap()
|
||||
}
|
||||
None => serve_path("200.html".to_owned()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user