Support resolving static resources at halo work directory (#4285)

#### 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
支持静态资源映射
```
pull/4287/head
John Niang 2023-07-24 16:24:34 +08:00 committed by GitHub
parent 9bea5ef1c9
commit 5ce47190fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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);
} }