更新时间:2023-08-15 GMT+08:00
分享

CORS

当一个资源向该资源所在服务器的不同的域发起请求时,就会产生一个跨域的HTTP请求。出于安全原因,浏览器会限制从脚本发起的跨域HTTP请求。通过跨域资源共享CORS机制可允许Web应用服务器进行跨域访问控制,使跨域数据传输安全进行。

YAML设置如下(根据实际需求调整配置参数):

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route
spec:
  hosts:
  - ratings.prod.svc.cluster.local
  http:
  - route:
    - destination:
        host: ratings.prod.svc.cluster.local
        subset: v1
    corsPolicy:                   # 配置跨域资源共享
      allowOrigins:
      - exact: https://example.com
      allowMethods:
      - POST
      - GET
      allowCredentials: false
      allowHeaders:
      - X-Foo-Bar
      maxAge: "24h"

相关文档