mirror of https://github.com/realaravinth/gitpad
feat: setup cache busting for static assets
parent
fc40706ca9
commit
9249dc3567
|
@ -2,3 +2,5 @@
|
|||
.env
|
||||
tarpaulin-report.html
|
||||
**/tmp/
|
||||
assets
|
||||
src/cache_buster_data.json
|
||||
|
|
30
build.rs
30
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();
|
||||
}
|
||||
|
|
|
@ -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<Arc<data::Data>>;
|
||||
pub type DB = WebData<Box<dyn db_core::GPDatabse>>;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref FILES: FileMap = FileMap::new();
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
|
|
Loading…
Reference in New Issue