【问题标题】:Azure Web App Websockets CORS: Access-Control-Allow-OriginAzure Web App Websockets CORS:访问控制允许来源
【发布时间】:2017-05-22 17:33:51
【问题描述】:

我正在开发一个 API(使用 Node.js)并将 Socket.io 与 Express 一起使用,我遇到了一些关于 CORS 的错误,我在 localhost 中使用 Express 和 Socket.io 2.0 解决了这个问题,这与 *.azurewebsites 一起使用。净,但不再有效。

Express 测试(见控制台):http://crawlerbackend.azurewebsites.net/test_cors_express_azure.html

Socket.io 测试(见控制台):http://crawlerbackend.azurewebsites.net/test_cors_socketio_azure.html

但我需要向所有人公开我的 Socket.io API,因为我的客户需要它,并在 Heroku 中测试了相同的文件:

Express 测试(见控制台):https://testcrawlersite.herokuapp.com/test_cors_express_azure.html

Socket.io 测试(见控制台):https://testcrawlersite.herokuapp.com/test_cors_socketio_azure.html

我根据他们的文档遵循最佳 Express 和 Socket.io 实践。我有一个独特的结论,我需要在 IISNode 中进行配置吗?还是在门户中?与“CORS”选项不同(使用 * 设置)。

这是错误:

XMLHttpRequest cannot load https://crawlerbackend.azurewebsites.net/socket.io/?EIO=3&transport=polling&t=LmW1TfL. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'https://testcrawlersite.herokuapp.com' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

【问题讨论】:

    标签: node.js azure websocket azure-web-app-service


    【解决方案1】:

    您可以启用Web Sockets 让 Socket.io 使用 WebSockets 而不是长轮询。 WebSockets 没有同源策略。

    要使用 Azure Portal 启用 WebSocket,请从 Web 应用刀片中单击 Web 应用,然后单击 所有设置 > 应用设置。在 Web Sockets 下,点击 On。然后点击保存

    更多信息,请参考Create a Node.js chat application with Socket.IO in Azure App Service

    【讨论】:

      猜你喜欢
      • 2019-02-09
      • 2016-06-02
      • 2021-09-07
      • 2016-06-27
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 2020-11-26
      相关资源
      最近更新 更多