gpt4 book ai didi

rest - CORS 与 3scale

转载 作者:可可西里 更新时间:2023-11-01 17:05:47 24 4
gpt4 key购买 nike

我们正尝试在 OpenShift 上设置一个 3scale 平台,以管理 REST 服务和 JavaScript 网络应用程序之间的 API 访问。身份验证应使用放置在 HTTP header 中的用户 key 进行管理。这两个应用程序可通过不同的 URL 访问:

JS web application:     http://siteA.example.com
REST API application: http://siteB.example.com

所以我们正在使用 CORS 在 webapp 上实现跨源资源。这引入了浏览器在没有用户 key header 的情况下发送的几个 OPTIONS 飞行前请求,因此从 3scale 收到 HTTP 403 错误。

有没有办法避免这种行为?

最佳答案

如果你不能在应用程序级别处理它,那么你可以做一个 nginx if 语句来处理它。

location / {
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "http://example.com";
add_header Access-Control-Allow-Methods "GET, OPTIONS";
add_header Access-Control-Allow-Headers "Authorization";
add_header Access-Control-Allow-Credentials "true";
...
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
...
}

通过http://blog.rogeriopvl.com/archives/nginx-and-the-http-options-method/

关于rest - CORS 与 3scale,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44261553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com