代码拉取完成,页面将自动刷新
const express = require('express');
const router = require('./router');
const bodyParser = require('body-parser');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const history = require('connect-history-api-fallback')
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server)
let customer = {}
let business = {}
io.on('connection', (socket)=> {
// 用户登录
socket.on('lognIn', (data)=> {
customer[data] = socket
})
// 商家登录
socket.on('businessLogn',(data)=> {
business[data] = socket
})
// 发送消息
socket.on('msg',(data)=> {
// console.log(business)
for (let i in business) {
business[i].emit('sendToBusiness', data)
}
})
socket.on('replay', (data)=> {
customer[data.toId].emit('sendToCustomer', data)
})
})
app.use(session({
secret: 'motherandbobymall',
resave: false,
saveUninitialized: true,
// // cookie: { secure: true }
store: new MongoStore({
url: 'mongodb://localhost/motherandbobymall-session'
})
}))
app.use('/public/', express.static('./public/'))
app.use(express.static('./dist/'))
app.use('/public/', express.static('/public/'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extends: false}));
app.use(history({
// verbose: true,
index: '/'
}))
app.use(router)
server.listen('3000', function () {
console.log('running....')
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。