添加全局跨域配置
This commit is contained in:
parent
45879ba6f0
commit
6bbd3536b4
@ -6,6 +6,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* R
|
||||
* 返回响应
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/6/27 16:24:58
|
||||
|
29
src/main/java/com/huangge1199/picture/config/CorsConfig.java
Normal file
29
src/main/java/com/huangge1199/picture/config/CorsConfig.java
Normal 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("*");
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
|
||||
/**
|
||||
* ErrorCode
|
||||
* 异常信息
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/6/27 16:26:54
|
||||
|
Loading…
Reference in New Issue
Block a user