14. CORS 配置
您可以配置网关来控制 CORS 行为。“全局”CORS 配置是 URL 模式的映射Spring 框架CorsConfiguration
.
以下示例配置 CORS:
示例 69.application.yml
spring:
cloud:
gateway:
globalcors:
cors-configurations:
'[/**]':
allowedOrigins: "https://docs.spring.io"
allowedMethods:
- GET
在前面的示例中,允许来自源自docs.spring.io
对于所有 GET 请求的路径。
要为未由某些网关路由谓词处理的请求提供相同的 CORS 配置,请将spring.cloud.gateway.globalcors.add-to-simple-url-handler-mapping
属性设置为true
.
当您尝试支持 CORS 预检请求并且您的路由谓词未评估为true
因为 HTTP 方法是options
.