好的,这就是我的胶水清单。如您所见,正在设置cors对象,但从前端应用程序:localhost:3000运行时,我仍然收到此愚蠢的错误。
Access to XMLHttpRequest at 'http://localhost:8082/api/v1/check_out_order' from origin 'http://localhost:3000' 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.
"glueManifest": {
"server": {
"port": 8082,
"routes": {
"cors": {
"origin": ["*"],
"additionalHeaders": ["cache-control", "x-requested-with"]
}
}
},
任何可能对我有解决方案的人将不胜感激! TIA!
答案 0 :(得分:0)
尝试:var server= new Hapi.Server({ port: 8082, routes: { cors: true }});
答案 1 :(得分:0)
您的后端还需要在所有端点上接受“ OPTION”类型的HTTP请求,并将标头添加到所有响应中。
HTTP OPTIONS方法用于描述通信选项 目标资源。客户端可以为选项指定URL 方法或星号(*)表示整个服务器。
资源:https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
Access-Control-Allow-Origin响应标头指示是否 响应可以与来自给定源的请求代码共享。
资源:https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin