使用 Django 和 Vue.js 开发应用程序。我在 https://localhost:8000 上运行网站,在端口 8080 上运行前端作为本地 https 网格实例。在设置 header 之前,我不断收到每个 HTTP 请求的这种类型的 CORS 错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://u-redwood-testapplicationfrontend.grid.locked.com:8080/sockjs-node/info?t=1594916128605. (Reason: CORS request did not succeed). [Learn More]
通过在 webpack 配置文件中附加以下 header 来解决此问题:
headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
},
我还添加了带有 key 、证书和证书颁发机构的 https。在此之后,错误基本上消失了。但是,每当我 Ctrl+C 我的开发服务器时,我都会以 1-2-4-8-16-32-64-128-... 秒为增量收到上述错误,如下所示:
[WDS] Disconnected!
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://u-redwood-testapplicationfrontend.grid.locked.com:8080/sockjs-node/info?t=1594916128605. (Reason: CORS request did not succeed). [Learn More]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://u-redwood-testapplicationfrontend.grid.locked.com:8080/sockjs-node/info?t=1594916128605. (Reason: CORS request did not succeed). [Learn More]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://u-redwood-testapplicationfrontend.grid.locked.com:8080/sockjs-node/info?t=1594916128605. (Reason: CORS request did not succeed). [Learn More]
这是正常行为吗?这是 CORS 发送的某种 Keep-Alive 吗?
任何帮助,将不胜感激。
谢谢!
最佳答案
对我来说运行npm run build
/vue-cli-service build
然后重启serve
过程解决了这个问题。
在切换我正在工作的网络时,这似乎发生在我身上——虽然不完全确定解释是什么。
关于javascript - 使用 Ctrl+C 终止运行 Vue.js 的 webpack 后,sockjs-node Cross-Origin Request Blocked 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62944640/