跨域问题: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',

}

 
posted on 2022-05-12 08:28  super-brother  阅读(42)  评论(0编辑  收藏  举报