gpt4 book ai didi

node.js - Socket.io 可以在本地主机上运行,​​但不能在 Heroku 上运行

转载 作者:太空宇宙 更新时间:2023-11-04 01:17:29 24 4
gpt4 key购买 nike

我设法让套接字在我的 LocalHost 上工作,但是上传到 Heroku 时出现以下错误。

Heroku 日志:

2020-02-26T19:18:12.223451+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xsN8" host=evening-beach-84352.herokuapp.com request_id=9e085385-d06d-42f8-a02b-741ebdb50139 fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.268249+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtMN" host=evening-beach-84352.herokuapp.com request_id=560a1283-e9ad-4f98-b65d-c98e3af0d989 fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.340518+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtNI" host=evening-beach-84352.herokuapp.com request_id=0747c99f-bfa7-4a48-9dc9-396237ea4afd fwd="99.239.140.92" dyno=web.1 connect=1ms service=17ms status=404 bytes=417 protocol=https
2020-02-26T19:18:16.345722+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtNd" host=evening-beach-84352.herokuapp.com request_id=c28aa30e-c33f-4d2b-809d-7f723c9ad2f8 fwd="99.239.140.92" dyno=web.1 connect=1ms service=11ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:16.394512+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtOS" host=evening-beach-84352.herokuapp.com request_id=93635a58-6c21-4d1a-81b4-ba67c712bc4a fwd="99.239.140.92" dyno=web.1 connect=1ms service=3ms status=404 bytes=417 protocol=https
2020-02-26T19:18:18.146871+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtpq" host=evening-beach-84352.herokuapp.com request_id=8dc8077a-5719-4f97-bd60-dc2f9585efea fwd="99.239.140.92" dyno=web.1 connect=1ms service=5ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:18.104971+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=N22xtp6" host=evening-beach-84352.herokuapp.com request_id=1a135498-5911-4757-90a6-52f22188b3ae fwd="99.239.140.92" dyno=web.1 connect=1ms service=8ms status=200 bytes=1156 protocol=https
2020-02-26T19:18:18.174618+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtqB" host=evening-beach-84352.herokuapp.com request_id=dce824bb-5243-45be-bd9b-5be3026412ac fwd="99.239.140.92" dyno=web.1 connect=1ms service=3ms status=404 bytes=417 protocol=https
2020-02-26T19:18:18.235090+00:00 heroku[router]: at=info method=POST path="/socket.io/?EIO=3&transport=polling&t=N22xtr2" host=evening-beach-84352.herokuapp.com request_id=44dbc61d-5e40-4283-b602-77107c20bdcd fwd="99.239.140.92" dyno=web.1 connect=1ms service=7ms status=404 bytes=417 protocol=https

浏览器控制台日志:

polling-xhr.js:271 POST https://evening-beach-84352.herokuapp.com/socket.io/?EIO=3&transport=polling&t=N22yWHd 404 (Not Found)

我在我的客户端代码上进行了此设置:

import socketIOClient from "socket.io-client";

const socket = socketIOClient("https://evening-beach-84352.herokuapp.com/")

这是我的服务器端代码:

const server = require('http').Server(app);
const socketIO = require('socket.io')
const io = socketIO(server, { origin: "*:*" });

const PORT = process.env.PORT || 8080;

最佳答案

您是否在应用中启用了 session 亲和性?来自 support article :

Apps using Socket.io should enable session affinity. If you plan to use Node’s Cluster module or to scale your app to multiple dynos, you should also follow Socket.io’s multiple-nodes instructions.

heroku features:enable http-session-affinity

关于node.js - Socket.io 可以在本地主机上运行,​​但不能在 Heroku 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60421223/

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