From 731652baae37682ea18866ddb9edb6b71fa8d18d Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Thu, 21 Nov 2024 18:33:33 +0800 Subject: [PATCH 1/3] fix: judge devServer instead of writeToDisk --- crates/mako/src/dev.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/mako/src/dev.rs b/crates/mako/src/dev.rs index 6d5346508..19b454ab1 100644 --- a/crates/mako/src/dev.rs +++ b/crates/mako/src/dev.rs @@ -173,7 +173,7 @@ impl DevServer { // staticfile has 302 problems when modify tooooo fast in 1 second // it will response 302 and we will get the old file // TODO: fix the 302 problem? - if !context.config.write_to_disk { + if context.config.dev_server.is_none() { if let Some(res) = context.get_static_content(path_without_slash_start) { debug!("serve with context.get_static_content: {}", path); From ab8dd6fc55290b37dd6cf6c81b9002e03b8cf59b Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Fri, 22 Nov 2024 10:25:13 +0800 Subject: [PATCH 2/3] fix: add branch header --- crates/mako/src/dev.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/mako/src/dev.rs b/crates/mako/src/dev.rs index 19b454ab1..1245158de 100644 --- a/crates/mako/src/dev.rs +++ b/crates/mako/src/dev.rs @@ -173,7 +173,7 @@ impl DevServer { // staticfile has 302 problems when modify tooooo fast in 1 second // it will response 302 and we will get the old file // TODO: fix the 302 problem? - if context.config.dev_server.is_none() { + if context.config.write_to_disk { if let Some(res) = context.get_static_content(path_without_slash_start) { debug!("serve with context.get_static_content: {}", path); @@ -196,6 +196,8 @@ impl DevServer { Ok(hyper::Response::builder() .status(hyper::StatusCode::OK) .header(CONTENT_TYPE, content_type) + .header(CACHE_CONTROL, "no-cache") + .header(ACCESS_CONTROL_ALLOW_ORIGIN, "*") .body(hyper::Body::from(bytes)) .unwrap()) }); From 052e10ebb50708e52dfda5b82252918910fd9170 Mon Sep 17 00:00:00 2001 From: pshu Date: Sat, 23 Nov 2024 00:08:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=F0=9F=8E=A8=20static=20file=20?= =?UTF-8?q?with=200=20ages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/mako/src/dev.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/mako/src/dev.rs b/crates/mako/src/dev.rs index 1245158de..0dae20352 100644 --- a/crates/mako/src/dev.rs +++ b/crates/mako/src/dev.rs @@ -72,8 +72,12 @@ impl DevServer { Ok::<_, hyper::Error>(service_fn(move |req| { let context = context.clone(); let txws = txws.clone(); - let staticfile = - hyper_staticfile::Static::new(context.config.output.path.clone()); + let staticfile = { + let mut sf = + hyper_staticfile::Static::new(context.config.output.path.clone()); + sf.cache_headers(Some(0)); + sf + }; async move { Self::handle_requests(req, context, staticfile, txws).await } })) } @@ -173,7 +177,7 @@ impl DevServer { // staticfile has 302 problems when modify tooooo fast in 1 second // it will response 302 and we will get the old file // TODO: fix the 302 problem? - if context.config.write_to_disk { + if !context.config.write_to_disk { if let Some(res) = context.get_static_content(path_without_slash_start) { debug!("serve with context.get_static_content: {}", path);