Updated on 2025-04-25 GMT+08:00

CORS

When a resource is requested from another domain outside the domain from which the resource is originated, a cross-origin HTTP request is generated. For security purposes, the browser restricts the cross-origin HTTP request from being initiated from a script. If cross-origin resource sharing (CORS) is enabled, the web application server can control cross-origin requests, ensuring secure data transmission.

Configure the YAML file as follows:

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:                   # Configure CORS.
      allowOrigins:
      - exact: https://example.com
      allowMethods:
      - POST
      - GET
      allowCredentials: false
      allowHeaders:
      - X-Foo-Bar
      maxAge: "24h"

You can configure the parameters based on site requirements.