Wrap server in header middleware with a sane CacheControl policy to satisfy lighthouse

This commit is contained in:
Imbus 2024-03-08 05:08:00 +01:00
parent 71bbd3bfbd
commit 68fca7cbde

View file

@ -1,5 +1,6 @@
use actix_cors::Cors;
use actix_files::Files;
use actix_web::http::header::{CacheControl, CacheDirective};
use actix_web::middleware;
use actix_web::web::Data;
use actix_web::{web::scope, App, HttpServer};
@ -55,6 +56,10 @@ async fn main() -> std::io::Result<()> {
.wrap(middleware::Compress::default())
.wrap(middleware::Logger::new("%s %r"))
.wrap(middleware::NormalizePath::trim())
.wrap(
middleware::DefaultHeaders::new()
.add(CacheControl(vec![CacheDirective::MaxAge(31536000)])),
)
.service(
scope("/api")
.service(get_posts)