当spring cloud gateway出现CORS问题的解决方案

2022-07-04 13:08:53

在application.yml中配置如下即可

spring:
  application:
    name: API-GATEWAY
  cloud:
    nacos:
      server-addr: 你的nacos地址:8848
    gateway:
      routes:
        - id: router
          uri: lb:// 负载均衡写法
          predicates:
            - Path=/fu/ck/*
          filters:
            - StripPrefix=1
            - Token=true
      globalcors: #跨域问题
        cors-configurations:
          '[/**]':				
            allowedOrigins:
              - "http://localhost:8080"   
            allowedHeaders:
                - "*"
            allowCredentials: true
            maxAge: 360000
            allowedMethods:
              - GET
              - POST
              - DELETE
              - PUT
              - OPTIONS
              - HEAD
          default-filters:
            - DedupeResponseHeader=Vary Access-Control-Allow-Origin Access-Control-Allow-Credentials, RETAIN_FIRST
  • 作者:coding小黄
  • 原文链接:https://blog.csdn.net/fashion_h/article/details/120582908
    更新时间:2022-07-04 13:08:53