如何在我的nodejs后端服务器上设置多个socketio实例?

时间:2020-06-05 01:08:47

标签: node.js mongodb mongoose socket.io

我目前有一个后端server.js:

import config from './../config/config'
import app from './express'
import mongoose from 'mongoose'
import bidding from './controllers/bidding.controller'
import chatroom from './controllers/chatroom.controller'
// Connection URL
mongoose.Promise = global.Promise
mongoose.connect(config.mongoUri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify: false })
mongoose.connection.on('error', () => {
  throw new Error(`unable to connect to database: ${config.mongoUri}`)
})

const server = app.listen(config.port, (err) => {
  if (err) {
    console.log(err)
  }
  console.info('Server started on port %s.', config.port)
})


bidding(server)

我希望能够为聊天室附加另一个套接字连接。现在,我可以将服务器作为参数传递给bidding()或chatroom(),但不能两者都传递。最好的方法是什么?

  • 提前谢谢!

0 个答案:

没有答案