跨域问题
作者:互联网
跨域问题:spring
springmvcConfig配置:
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE");
}
}
yaml配置:
#以下为 跨域配置
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Origin, RETAIN_UNIQUE
globalcors:
cors-configurations:
'[/**]':
allow-credentials: true # 允许携带认证信息
allowedOrigins: "*" # 允许跨域的源(网站域名/ip),设置*为全部
allowedMethods: "*" # 允许跨域的method, 默认为GET和OPTIONS,设置*为全部
allowedHeaders: "*" # 允许跨域请求里的head字段,设置*为全部
egg:
config.default.js配置
//跨域配置 如果不配置security,会报403错误
config.security = {
csrf: {
enable: false,
ignoreJSON: true,
},
domainWhiteList: ['*'],
}
//跨域配置
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
}
plugin.js 配置
//跨域配置
cors = {
enable: true,
package: 'egg-cors',
}
标签:跨域,GET,config,配置,问题,cors,true 来源: https://www.cnblogs.com/super-brother/p/16260815.html