解决跨域访问问题

This commit is contained in:
luke 2025-05-24 09:23:34 +08:00
parent 62791e5553
commit 957d97cf98

View File

@ -0,0 +1,21 @@
package com.doc.parser.infrastructure.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("/**")
.allowedOrigins("*") // 推荐指定为 "chrome-extension://<插件ID>",测试可用 "*"
.allowedMethods("POST", "GET", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(false); // POST 请求建议设置 false,避免携带 cookie
}
}