higress解决跨域问题

跨域问题是什么:

        不同协议、端口或者路由的情况下尝试访问,比如你新建一个服务运行在http的8081端口上但是尝试访问一个https的31309端口的服务就是跨域问题

表现:

        把网页的console调出来,访问路由的时候会有类似这种:
 

test.html:1 Access to fetch at 'http://192.168.64.20:31309/xxx' from origin 'http://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled

如何解决:

        在外部能通过网关访问到服务的情况下(higress之:让流量通过gateway-优快云博客),设置跨域配置:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-python-ingress
  annotations:
    # Higress专用CORS配置
    higress.io/enable-cors: "true"    # 这里不要写成cors-enable,都是血泪,这篇博客就是这个配置导致产生的
    higress.io/cors-allow-origin: "http://localhost:8081"
    higress.io/cors-allow-methods: "GET,POST,OPTIONS"
    higress.io/cors-allow-headers: "DNT,Content-Type,Authorization"
    higress.io/cors-allow-credentials: "true"
    higress.io/cors-max-age: "1728000"

spec:
  ingressClassName: higress
  rules:
  - host: foo.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: foo-python
            port:
              number: 8080

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值