【问题标题】:Websockets to Heroku are giving a 404 on chrome/firefoxHeroku 的 Websockets 在 chrome/firefox 上给出 404
【发布时间】:2020-11-08 09:28:43
【问题描述】:

我的 Django 应用程序部署在 heroku 上。它使用 websockets,一切都配置正确。当我访问我的站点时,websockets 以WebSocket connection to 'wss://<url>' failed: Error during WebSocket handshake: Unexpected response code: 404 失败。我做了一些挖掘,这显然是由于 chrome 阻塞了 websockets?我遇到了this issue,这听起来像是我得到的,但答案并没有为我解决。

有人可以解释这里发生了什么,以及如何解决它吗?

【问题讨论】:

    标签: javascript django google-chrome heroku websocket


    【解决方案1】:

    尝试使用https://<url> 尽管使用wss 我在heroku 上部署我的node.js 应用程序时遇到了同样的问题。 希望这也能解决您的问题。

    【讨论】:

    • 我现在得到Uncaught DOMException: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'https' is not allowed.
    【解决方案2】:

    所以解决方案与 heroku 无关。我正在使用 gunicorn 来部署我的应用程序,但它不支持 websockets,所以当网站访问我的 websocket 端点时,gunicorn 会返回 404。我切换到 daphne,并将 web: daphne <application>.asgi:application --port $PORT --bind 0.0.0.0 添加到 Procfile 中,一切都开始工作了。 Heroku 的 This blog post 帮助了我,特别是 This segment

    【讨论】:

      猜你喜欢
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 2020-06-06
      • 2015-07-18
      • 1970-01-01
      • 2013-11-13
      相关资源
      最近更新 更多