120. CORS 配置

可以将网关配置为控制 CORS 行为。 “全局” CORS 配置是 URL 模式到Spring Framework CorsConfiguration的 Map。

application.yml.

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

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