package com.estate.expert.admin.config;
|
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
/**
|
* 跨域配置
|
* @author ligf
|
* @Description
|
* @date 2023-07-10
|
**/
|
@Slf4j
|
@Configuration
|
public class CorsConfig implements WebMvcConfigurer {
|
@Override
|
public void addCorsMappings(CorsRegistry registry) {
|
log.info("addCorsMappings");
|
registry.addMapping("/**")
|
// .allowedOrigins("*") // 允许的来源域名
|
.allowedOriginPatterns("*")
|
.allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的HTTP方法
|
.allowedHeaders("*") // 允许的请求头
|
.allowCredentials(true) // 允许发送身份验证信息(如Cookies)
|
.maxAge(3600); // 预检请求(OPTIONS)的缓存时间,单位秒
|
}
|
}
|