节点JS 404错误与Socket.IO和上传Heroku

时间:2018-03-15 21:44:24

标签: node.js heroku socket.io

我被困在这几个小时。我可以在本地运行代码,但是当我尝试在heroku上部署时,它会在我的套接字上抛出404错误。

服务器代码

'use strict';

const express = require('express');
const socketIO = require('socket.io');
const path = require('path');
const PORT = process.env.PORT || 3000;

const server = express()
.use(express.static('public'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
const io = socketIO(server);

io.on('connection', (socket) =>{
console.log("connection to socket", socket.id);
});

客户代码:

var socket = io();
socket.emit('email', {
        fullName: fullName.value,
        numOfGuest: numOfGuest.value,
        guestName: guestName.value,
        emailAddress: emailAddress.value,
        guestStatus: status
    });

1 个答案:

答案 0 :(得分:0)

使用Socket.io的应用应启用会话亲和力。

heroku features:enable http-session-affinity

有关heroku的会话亲和力的更多信息:https://devcenter.heroku.com/articles/session-affinity