Update API and WebSocket base URLs to use environment variables for better configuration management

This commit is contained in:
liu
2026-01-30 00:45:04 +08:00
parent 197ce5e7ea
commit 246515b43e
11 changed files with 310 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
package com.music.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;
import java.io.IOException;
/**
* 生产环境:前端 SPA 由 Spring Boot 托管时,未匹配到的路径回退到 index.html。
*/
@Configuration
public class SpaForwardConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.resourceChain(true)
.addResolver(new PathResourceResolver() {
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
Resource resource = location.createRelative(resourcePath);
if (resource.exists() && resource.isReadable()) {
return resource;
}
// SPA 路由回退到 index.html
return location.createRelative("index.html");
}
});
}
}