mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-02 00:16:11 +08:00
feat(cors): 全局启用CORS支持
在Spring应用中通过配置CORS实现跨域请求支持,允许所有来源、方法和头。 此变更有助于解决前端应用在不同域上运行时的跨域问题。
This commit is contained in:
parent
f6fcfb8ed0
commit
3df62cebbe
23
src/main/java/top/suyiiyii/sims/common/CorsConfig.java
Normal file
23
src/main/java/top/suyiiyii/sims/common/CorsConfig.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package top.suyiiyii.sims.common;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WebMvcConfigurer corsConfigurer() {
|
||||||
|
return new WebMvcConfigurer() {
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**")
|
||||||
|
.allowedOrigins("*")
|
||||||
|
.allowedMethods("*")
|
||||||
|
.allowedHeaders("*");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user