|
|
@@ -0,0 +1,20 @@
|
|
|
+package com.smart.reader.config;
|
|
|
+
|
|
|
+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 implements WebMvcConfigurer {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addCorsMappings(CorsRegistry registry) {
|
|
|
+ registry.addMapping("/api/**") // 指定需要跨域的路径
|
|
|
+ .allowedOrigins("http://localhost:5173") // 允许的源
|
|
|
+ .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
|
|
|
+ .allowedHeaders("*") // 允许的头信息
|
|
|
+ .exposedHeaders("X-Custom-Header") // 暴露给前端的头部
|
|
|
+ .maxAge(3600) // 预检请求的有效期(单位:秒)
|
|
|
+ .allowCredentials(true); // 是否允许发送Cookie
|
|
|
+ }
|
|
|
+}
|