119. CORS Configuration

网关可以配置为控制 CORS 行为。 “global”CORS configuration 是Spring Framework CorsConfiguration的 URL 模式的 map。

application.yml.

spring:
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
            allowedOrigins: "docs.spring.io"
            allowedMethods:
            - GET

在上面的例子中,对于所有 GET 请求的_path,来自 docs.spring.io 的请求将允许 CORS 请求。