init local code
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package com.yunhai.cms.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.filter.ForwardedHeaderFilter;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Web 静态资源装配。
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@code /upload/**} → FILE_PATH 本地磁盘(正文图片/轮播图/友链 Logo,双 key 约定方案 §7.3);</li>
|
||||
* <li>{@code /admin/**} → 管理端 SPA(front 构建产物拷入 classpath:/static/admin/,
|
||||
* hash 路由 + 相对 base,天然支持子路径部署);</li>
|
||||
* <li>根路径与 /admin 跳管理端入口。</li>
|
||||
* </ul>
|
||||
* 门户主题资产不在此处:按站点皮肤包解析,见 PortalAssetController。
|
||||
*/
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${FILE_PATH:./upload/}")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* X-Forwarded-Proto/Host/Port 头处理(B-2):反代(Caddy/nginx)形态下
|
||||
* request.getScheme()/getServerName()/getServerPort() 修正为对外值,
|
||||
* 使 public_base_url/base-origin 均未配置时的请求派生 URL 不携带内网 scheme/端口。
|
||||
* 仅应在可信反代之后部署(直连暴露时该头可伪造,只影响派生形态展示,不影响数据)。
|
||||
*/
|
||||
@Bean
|
||||
public ForwardedHeaderFilter forwardedHeaderFilter() {
|
||||
return new ForwardedHeaderFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
String root = filePath.endsWith("/") || filePath.endsWith("\\") ? filePath : filePath + "/";
|
||||
registry.addResourceHandler("/upload/**")
|
||||
.addResourceLocations("file:" + new File(root).getAbsolutePath().replace('\\', '/') + "/");
|
||||
registry.addResourceHandler("/admin/**")
|
||||
.addResourceLocations("classpath:/static/admin/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addRedirectViewController("/", "/admin/index.html");
|
||||
registry.addRedirectViewController("/admin", "/admin/index.html");
|
||||
registry.addRedirectViewController("/admin/", "/admin/index.html");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user