-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
85 lines (69 loc) · 2.08 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// var express = require('express');
var mongoose = require('mongoose');
var path = require("path");
var async = require('async');
var colors = require('colors');
var bodyParser = require('body-parser');
var express = require('express'),
app = express(),
http = require('http'),
server = http.Server(app),
io = require('socket.io')(server);
async.series([
/*
* Setup the database connection
*/
function(callback) {
var db = mongoose.connection;
db
.on('error', function(err) {
process.stdout.write(['[', '✗'.red, ']', 'Database connection'].join(' ') + '\n');
callback(err);
})
.once('open', function() {
process.stdout.write(['[', '✓'.green, ']', 'Database connection'].join(' ') + '\n');
callback();
});
mongoose.connect('mongodb://localhost/quiz');
},
/*
* Setup the webserver
*/
function(callback) {
// Code to setup the Express app (middleware, routes) can go here. For example:
app.use(express.static(path.join(__dirname, 'clientside')));
// setup the body parser for reading JSON
app.use(bodyParser.json());
// routing:
// Quizmaster route:
var quizMasterRoute = require('./routes/quizmaster');
app.use('/quizmaster/', quizMasterRoute);
// scoreboard route:
var scoreboardRoute = require('./routes/scoreboard');
app.use('/scoreboard/', scoreboardRoute);
// team route:
var teamRoute = require('./routes/team');
app.use('/team/', teamRoute);
server.listen( 1337,
function() {
console.log("The Server is lisening on port 1337.")
});
callback();
/*
* Setup the websockets
*/
}, function(callback) {
require('./socket/socket.js')(io);
callback();
}
], function(err, result) {
if (err) {
process.stdout.write(err.red);
} else {
process.stdout.write(['[', '✓'.green, ']', 'All systems up and running'].join(' ') + '\n');
}
});
process.on('exit', function(code) {
process.stdout.write(['[', '✗'.red, ']', 'Application quit [', code, ']'].join(' ') + '\n')
});
// code to setup event listeners for WebSocket communication can go here