微服务网关跨域配置
跨域配置
有時候,我們需要對所有微服務跨域請求進行處理,則可以在gateway中進行跨域支持。修改application.yml,添加如下代碼:
spring:cloud:gateway:globalcors:cors-configurations:'[/**]': # 匹配所有請求allowedOrigins: "*" #跨域處理 允許所有的域allowedMethods: # 支持的方法- GET- POST- PUT- DELETE最終文件如下:
spring:cloud:gateway:globalcors:cors-configurations:'[/**]': # 匹配所有請求allowedOrigins: "*" #跨域處理 允許所有的域allowedMethods: # 支持的方法- GET- POST- PUT- DELETEapplication:name: gateway-web server:port: 8001 eureka:client:service-url:defaultZone: http://127.0.0.1:7001/eurekainstance:prefer-ip-address: true management:endpoint:gateway:enabled: trueweb:exposure:include: true?
總結(jié)
- 上一篇: 微服务网关搭建
- 下一篇: 微服务网关路由过滤作用介绍