-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (22 loc) · 836 Bytes
/
Copy pathindex.js
File metadata and controls
31 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const router = require('./config/router')
const { port, dbUri } = require('./config/environment')
const mongoose = require('mongoose')
mongoose.Promise = require('bluebird')
mongoose.connect(dbUri)
app.use(express.static(`${__dirname}/public`))
app.use(bodyParser.json())
app.use('/api', router)
app.get('/*', (req, res) => res.sendFile(`${__dirname}/public/index.html`))
const server = app.listen(port, () => console.log(`Express is listening on port ${port}`))
const socket = require('socket.io')
const io = socket(server)
io.on('connection', (socket) => {
console.log(`socket is running, socket id: ${socket.id}`)
socket.on('sendMessage', function(data) {
io.emit('receiveMessage', data)
})
})
module.exports = app