package com.ewaytek.deepseek.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author yangtq * @date 2025/2/26 */ @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**") .addResourceLocations("classpath:/static/"); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") // 允许所有路径的跨域请求 .allowedOriginPatterns("*") // 使用 allowedOriginPatterns 替代 allowedOrigins .allowCredentials(true) // 允许发送 Cookie .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的 HTTP 方法 .allowedHeaders("*") // 允许的 HTTP 头部 .maxAge(3600); // 预检请求的缓存时间(秒) } }