diff --git a/.gitignore b/.gitignore index 4d8dc59..37da890 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .env tarpaulin-report.html **/tmp/ +assets +src/cache_buster_data.json diff --git a/build.rs b/build.rs index ab99a50..77d9e05 100644 --- a/build.rs +++ b/build.rs @@ -16,6 +16,8 @@ */ use std::process::Command; +use cache_buster::{BusterBuilder, NoHashCategory}; + fn main() { let output = Command::new("git") .args(&["rev-parse", "HEAD"]) @@ -23,4 +25,32 @@ fn main() { .expect("error in git command, is git installed?"); let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GIT_HASH={}", git_hash); + + cache_bust(); +} + +fn cache_bust() { + // until APPLICATION_WASM gets added to mime crate + // PR: https://github.com/hyperium/mime/pull/138 + // let types = vec![ + // mime::IMAGE_PNG, + // mime::IMAGE_SVG, + // mime::IMAGE_JPEG, + // mime::IMAGE_GIF, + // mime::APPLICATION_JAVASCRIPT, + // mime::TEXT_CSS, + // ]; + + println!("cargo:rerun-if-changed=static/cache"); + let no_hash = vec![NoHashCategory::FileExtentions(vec!["wasm"])]; + + let config = BusterBuilder::default() + .source("./static/cache/") + .result("./assets") + .no_hash(no_hash) + .follow_links(true) + .build() + .unwrap(); + + config.process().unwrap(); } diff --git a/src/main.rs b/src/main.rs index 77cf89f..87329c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,9 @@ use actix_web::{ error::InternalError, http::StatusCode, middleware as actix_middleware, web::Data as WebData, web::JsonConfig, App, HttpServer, }; +use lazy_static::lazy_static; use log::info; +use static_assets::FileMap; mod api; pub mod data; @@ -50,6 +52,10 @@ pub const PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE"); pub type AppData = WebData>; pub type DB = WebData>; +lazy_static! { + pub static ref FILES: FileMap = FileMap::new(); +} + #[cfg(not(tarpaulin_include))] #[actix_web::main] async fn main() -> std::io::Result<()> {