-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
35 lines (23 loc) · 801 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
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser')
const registerRoutes = require('./routes');
var app = express();
var server = null;
var io;
if(!module.parent){
server = app.listen(3000,function(){ console.log('AWM Server started!'); });
app.use( bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({extended: true})); // to support URL-encoded bodies
app.use(express.static(__dirname + '/public'));
app.use(cookieParser());
//Listen on the "/event" namespace
io = require('socket.io')(server);
io.of('/events').on('connection', function(socket){
socket.on('disconnect', function() {
socket.disconnect();
});
});
}
registerRoutes(app,io);
module.exports.app = app;