我想和socket.io一起运行Hapi.js.如果我使用相同的服务器为socket.io和hapi应用程序提供单独的连接,那将是很好的,因为我想在我的套接字中使用Hapi auth cookie
我尝试了一些解决方案,但它们都没有工作,我的服务器崩溃了.我尝试在hapi和我的应用程序启动的同一端口上运行socket.io,但我收到"找不到此localhost页面"错误.我做错了什么?任何帮助将不胜感激
这是我的代码:
const Hapi = require('hapi');
const server = new Hapi.Server();
const Config = require('./config/config.js');
const port = Number(process.env.PORT || 3000);
const io = require("socket.io")(port);
server.connection({
port: port
});
// my routes are here...
io.on("connection", function (socket) {
console.log('connected');
// Do all the socket stuff here.
})
server.start(function(err) {
if (err) {
console.error(err);
throw err;
}
console.log('Server started at %s', server.info.uri);
});
Run Code Online (Sandbox Code Playgroud)