我需要使用herokuapp设置socket.io服务器,该服务器响应404并且不加载任何内容。
我尝试使用index.js文件中的以下设置运行node.js服务器本地主机: const User = require('./ user') ,io = require('socket.io')(1337) 在localhost上运行良好。
To setup the server, i entered the following commands in the server directory:
-heroku login
-git init
-heroku git:clone -a example
-New-Item Procfile -type file
-git add .
-git commit -m "ready for heroku"
-git push heroku master
//Procfile
web: node index.js
//index.js
const User = require('./user')
, io = require('socket.io')(process.env.PORT || 1337)
/ *其余服务器代码* /
答案 0 :(得分:0)
如果您遵循:https://devcenter.heroku.com/articles/node-websockets
使用Socket.io的应用应启用会话亲缘关系。如果您打算使用节点的“群集”模块或将您的应用程序扩展到多个测功机,则还应遵循Socket.io的多节点说明。
heroku features:enable http-session-affinity
const io = require('socket.io')(process.env.PORT || 1337, {
pingInterval: 15000,
pingTimeout: 30000
});
使用:https://socket.io/docs/server-api/和https://lxcid.com/2017/06/03/socket.io-heroku/