go - 在React Web中使用Axios的Access Control Origin Header错误在Chrome和后端中使用Envoy进行反向代理抛出错误

标签 go cors axios grpc envoyproxy

我的后端服务器是grpc服务器(由Golang写),Envoy用于反向代理,它在端口:8080上运行具有配置cors:
cors: allow_origin_string_match: - safe_regex: google_re2: {} regex: \* allow_methods: GET, PUT, DELETE, POST, OPTIONS, PATCH allow_headers: authorization, keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout max_age: "1728000" expose_headers: custom-header-1,grpc-status,grpc-message
在前端,我使用React库Axios调用服务器的API。被浏览器阻止,并显示以下错误:

Access to XMLHttpRequest at 'http://localhost:8080/api/books/d23ea317-e667-449c-a77d-495859e37d30/bookfiles' from origin 'http://localhost:5000' 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.

浏览器阻止或使节配置有什么问题?

最佳答案

http。服务器必须响应标头在cors中具有Access-Control-Allow-OriginAccess-Control-Allow-Origin值需要是请求Origin标头值或const值,相对而言,新的浏览器不支持Access-Control-Allow-Origin标头值为*
您在chrome网络中检查响应标头。

关于go - 在React Web中使用Axios的Access Control Origin Header错误在Chrome和后端中使用Envoy进行反向代理抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61138453/

相关文章:

Golang - 意外的多分配行为

authentication - Nuxt Auth - 未设置用户数据

javascript - 如何使用 Jest 模拟构造函数状态初始化

ios - MacO 和 iO 上 Safari 的 React 和 Axios GET 请求问题

multithreading - go map 结构是线程安全的吗?

python-3.x - Goroutines vs asyncio 任务 + CPU 绑定(bind)调用的线程池

cordova - Meteor 中的 CORS 与 Cordova

node.js - AWS Api Gateway 未在 204 上设置 CORS

php - CORS header 在浏览器中被更改,导致内容被阻止

html - 为什么我的模板没有在浏览器中呈现?