feature: 允许跨源调用

This commit is contained in:
ClovertaTheTrilobita 2025-07-01 02:57:33 +08:00
parent b2960541ba
commit ae1c7b06f7

View file

@ -0,0 +1,17 @@
package com.cloverta.webapi.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("*") // 允许所有来源
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
.allowedHeaders("*") // 允许所有头部
.maxAge(3600); // 预检请求缓存时间
}
}