CORS错误

32 阅读1分钟

说明:记录一次CORS(跨域)错误,及解决方法。

场景

在vscode里面运行前端项目,idea中运行后端项目,登录时,访问接口,报CORS错误,如下:

在这里插入图片描述

解决

在后端项目的网关配置中,增加以下配置,注意层级结构

spring:
  cloud:
    gateway:
      globalcors:
        cors-configurations:
          '[/**]':
            allowed-origin-patterns: '*'
            allowedMethods:
              - GET
              - POST
              - HEAD
              - PUT
              - DELETE
            allowedHeaders: '*'
            allowCredentials: true

另外

跨域问题介绍,参考下面这篇文章:

首次发布

hezhongying.blog.csdn.net/article/det…