This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
107 lines (81 loc) · 2.61 KB
/
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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* Module dependencies.
*/
var
express = require('express'),
path = require('path'),
passport = require('passport'),
ymlConfig = require('yaml-config'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
SessionStore = require("session-mongoose")(express)
;
var conf = ymlConfig.readConfig(__dirname + '/config.yml',app.get('env'));
app.set('conf',conf);
app.set('db',require(__dirname+'/inc/db'));
// all environments
app.set('port', process.env.PORT || conf.server.port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
// Session
var sessionStore = new SessionStore({
interval: 3600*24*30*1000,
connection: app.get('db').db.connection // <== custom connection
});
var cookieParser = express.cookieParser(conf.server.secretkey);
app.set('sessionStore',sessionStore);
app.set('cookieParser',cookieParser);
app.use(cookieParser);
app.use(express.session({
key: conf.server.sessioncookie,
store: sessionStore,
secret: conf.server.secretkey,
cookie: {maxAge: 3600*24*31*365*1000 },
}));
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.locals.moment = require('moment');
require('./inc/login').app(app,passport);
function addLocals(req,res,next){
res.locals.user = req.user;
res.locals.appName = conf.app.title;
res.locals.path = req.path;
next();
}
app.get('*',addLocals);
app.post('*',addLocals);
var
routes = require('./routes'),
adminRoutes = require('./routes/admin'),
matchRoutes = require('./routes/match'),
testcomponent = require('./routes/testcomponent')
;
// Index
app.get('/', routes.index);
// Events
app.get('/event/:eventid', routes.eventDetail);
app.post('/event/:eventid', routes.eventDetail);
app.post('/newevent', routes.eventNew);
// Match
app.get('/match/:matchid', matchRoutes.matchDetail);
app.get('/match/:matchid/admin', matchRoutes.matchAdmin);
app.post('/match/:matchid/admin', matchRoutes.matchAdmin);
// Tests
app.get('/component', testcomponent.test);
// Admin
app.get('/admin/clubs', adminRoutes.clubs);
app.post('/admin/clubs', adminRoutes.clubs);
app.use(app.router);
require('./inc/sockets.js')(app,io);
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
server.listen(app.get('port'), function(){
console.log(conf.app.title+' server listening on port ' + app.get('port'));
});