From 5ce47190fa24a98d4575f1cd92fb5053a18a8e7b Mon Sep 17 00:00:00 2001 From: John Niang Date: Mon, 24 Jul 2023 16:24:34 +0800 Subject: [PATCH] Support resolving static resources at halo work directory (#4285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature /area core /milestone 2.8.x #### What this PR does / why we need it: Support resolving static resources at halo work directory `${halo.work-dir}/static/`. Please note that we only support adding static resources at hand by logging in the server. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/4087 #### Special notes for your reviewer: 1. Create a file `index.html` at `${halo.work-dir}/static` 2. Edit the file with any content 3. Browse with `http://localhost:8090/index.html` #### Does this PR introduce a user-facing change? ```release-note 支持静态资源映射 ``` --- .../src/main/java/run/halo/app/config/WebFluxConfig.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/application/src/main/java/run/halo/app/config/WebFluxConfig.java b/application/src/main/java/run/halo/app/config/WebFluxConfig.java index 64b03b14c..0fb0cea99 100644 --- a/application/src/main/java/run/halo/app/config/WebFluxConfig.java +++ b/application/src/main/java/run/halo/app/config/WebFluxConfig.java @@ -160,6 +160,13 @@ public class WebFluxConfig implements WebFluxConfigurer { }); }); + + var haloStaticPath = haloProp.getWorkDir().resolve("static"); + registry.addResourceHandler("/**") + .addResourceLocations(FILE_URL_PREFIX + haloStaticPath + "/") + .addResourceLocations(resourceProperties.getStaticLocations()) + .setCacheControl(CacheControl.noCache()) + .setUseLastModified(true); }