diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index c05ac49..285bb93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -113,20 +113,39 @@ async fn main() -> Result<()> { .and(with_state(state.clone())) .and_then(handlers::patrons); - let files = warp::path("static").and(warp::fs::dir("./static")); - let css = warp::path("css").and(warp::fs::dir("./css")); + let files = warp::path("static") + .and(warp::fs::dir("./static")) + .map(|reply| { + warp::reply::with_header( + reply, + "Cache-Control", + "public, max-age=86400, stale-if-error=60", + ) + }); + + let css = warp::path("css").and(warp::fs::dir("./css")).map(|reply| { + warp::reply::with_header( + reply, + "Cache-Control", + "public, max-age=86400, stale-if-error=60", + ) + }); + let sw = warp::path("sw.js").and(warp::fs::file("./static/js/sw.js")); let robots = warp::path("robots.txt").and(warp::fs::file("./static/robots.txt")); let favicon = warp::path("favicon.ico").and(warp::fs::file("./static/favicon/favicon.ico")); let jsonfeed = warp::path("blog.json") .and(with_state(state.clone())) + .and(warp::header::optional("if-none-match")) .and_then(handlers::feeds::jsonfeed); let atom = warp::path("blog.atom") .and(with_state(state.clone())) + .and(warp::header::optional("if-none-match")) .and_then(handlers::feeds::atom); let rss = warp::path("blog.rss") .and(with_state(state.clone())) + .and(warp::header::optional("if-none-match")) .and_then(handlers::feeds::rss); let sitemap = warp::path("sitemap.xml") .and(with_state(state.clone())) @@ -135,6 +154,7 @@ async fn main() -> Result<()> { let go_vanity_jsonfeed = warp::path("jsonfeed") .and(warp::any().map(move || "christine.website/jsonfeed")) .and(warp::any().map(move || "https://tulpa.dev/Xe/jsonfeed")) + .and(warp::any().map(move || "master")) .and_then(go_vanity::gitea); let metrics_endpoint = warp::path("metrics").and(warp::path::end()).map(move || { @@ -149,14 +169,37 @@ async fn main() -> Result<()> { .unwrap() }); - let site = index - .or(contact.or(feeds).or(resume.or(signalboost)).or(patrons)) - .or(blog_index.or(series.or(series_view).or(post_view))) + let static_pages = index + .or(feeds) + .or(resume.or(signalboost)) + .or(patrons) + .or(jsonfeed.or(atom.or(sitemap)).or(rss)) + .or(favicon.or(robots).or(sw)) + .or(contact) + .map(|reply| { + warp::reply::with_header( + reply, + "Cache-Control", + "public, max-age=86400, stale-if-error=60", + ) + }); + + let dynamic_pages = blog_index + .or(series.or(series_view).or(post_view)) .or(gallery_index.or(gallery_post_view)) .or(talk_index.or(talk_post_view)) - .or(jsonfeed.or(atom).or(rss.or(sitemap))) - .or(files.or(css).or(favicon).or(sw.or(robots))) + .map(|reply| { + warp::reply::with_header( + reply, + "Cache-Control", + "public, max-age=600, stale-if-error=60", + ) + }); + + let site = static_pages + .or(dynamic_pages) .or(healthcheck.or(metrics_endpoint).or(go_vanity_jsonfeed)) + .or(files.or(css)) .map(|reply| { warp::reply::with_header( reply, |
