-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (28 loc) · 836 Bytes
/
server.js
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
32
33
34
35
36
37
'use strict';
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.set('socketIo', io);
const port = 8000;
app.use(bodyParser.json());
app.use((err, req, res, next) => {
console.error(err);
// body-parser will set this to 400 if the json is in error
if (err.status === 400)
return res.status(err.status).send('Invalid Json format!');
return next(err);
});
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('disconnect', () => {
console.log('user disconnected');
});
});
require('./app/routes')(app, {});
http.listen(port, () => {
console.log('We are live on ' + port);
});
module.exports = app;