|
@@ -6,15 +6,15 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class CorsConfig implements WebMvcConfigurer {
|
|
public class CorsConfig implements WebMvcConfigurer {
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
- registry.addMapping("/api/**") // 指定需要跨域的路径
|
|
|
|
|
- .allowedOrigins("http://localhost:3000") // 允许的源
|
|
|
|
|
- .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
|
|
|
|
|
- .allowedHeaders("*") // 允许的头信息
|
|
|
|
|
- .exposedHeaders("X-Custom-Header") // 暴露给前端的头部
|
|
|
|
|
- .maxAge(3600) // 预检请求的有效期(单位:秒)
|
|
|
|
|
- .allowCredentials(true); // 是否允许发送Cookie
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// 由于在Vite配置了反向代理,因此不需要配置跨域了
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
+// registry.addMapping("/api/**") // 指定需要跨域的路径
|
|
|
|
|
+// .allowedOrigins("http://localhost:3000") // 允许的源
|
|
|
|
|
+// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
|
|
|
|
|
+// .allowedHeaders("*") // 允许的头信息
|
|
|
|
|
+// .exposedHeaders("X-Custom-Header") // 暴露给前端的头部
|
|
|
|
|
+// .maxAge(3600) // 预检请求的有效期(单位:秒)
|
|
|
|
|
+// .allowCredentials(true); // 是否允许发送Cookie
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|