添加全局跨域配置

This commit is contained in:
huangge1199 2025-06-27 16:39:20 +08:00
parent 45879ba6f0
commit 6bbd3536b4
3 changed files with 31 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import java.io.Serializable;
/** /**
* R * R
* 返回响应
* *
* @author huangge1199 * @author huangge1199
* @since 2025/6/27 16:24:58 * @since 2025/6/27 16:24:58

View File

@ -0,0 +1,29 @@
package com.huangge1199.picture.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* CorsConfig
* 全局跨域配置
*
* @author huangge1199
* @since 2025/6/27 16:37:44
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 覆盖所有请求
registry.addMapping("/**")
// 允许发送 Cookie
.allowCredentials(true)
// 放行哪些域名必须用 patterns否则 * 会和 allowCredentials 冲突
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.exposedHeaders("*");
}
}

View File

@ -4,6 +4,7 @@ import lombok.Getter;
/** /**
* ErrorCode * ErrorCode
* 异常信息
* *
* @author huangge1199 * @author huangge1199
* @since 2025/6/27 16:26:54 * @since 2025/6/27 16:26:54