|
@@ -0,0 +1,27 @@
|
|
|
|
|
+package space.anyi.serve.config;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
|
|
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @fileName: WebConfig
|
|
|
|
|
+ * @projectName: serve
|
|
|
|
|
+ * @package: space.anyi.serve.config
|
|
|
|
|
+ * @author: 杨逸
|
|
|
|
|
+ * @date:2026/4/28 10:51
|
|
|
|
|
+ * @description:
|
|
|
|
|
+ */
|
|
|
|
|
+@EnableWebMvc
|
|
|
|
|
+@Configuration
|
|
|
|
|
+public class WebConfig implements WebMvcConfigurer {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
+ registry.addMapping("/**") // 允许所有路径
|
|
|
|
|
+ .allowedOrigins("http://localhost:5173") // 允许的来源(可修改为前端地址)
|
|
|
|
|
+ .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的请求方法
|
|
|
|
|
+ .allowedHeaders("*") // 允许所有请求头
|
|
|
|
|
+ .allowCredentials(true); // 允许携带 Cookie
|
|
|
|
|
+ }
|
|
|
|
|
+}
|