-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (63 loc) · 2.05 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
// MODULES - EXPRESS
var express = require('express'),
routes = require('./routes'),
http = require('http');
// CONFIGURATION - EXPRESS SETUP
var app = express();
app.configure(function() {
app.set('port', process.env.PORT || 80);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret: 'example'
}));
app.use(checkAuth);
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.engine('html', require('hbs').__express);
app.set('views', __dirname + '/views/html');
app.set('view engine', 'html');
});
// CONFIGURATION - ERROR HANDELING OUTPUT
app.configure('development', function() {
app.use(express.errorHandler());
});
// AUTHORIZATION - JS AUTHORIZATION CHECK
function checkAuth(req, res, next) {
console.log('checkAuth ' + req.url);
// don't serve /secure to those not logged in
// you should add to this list, for each and every secure url
if (req.url === '/lms' && (!req.session || !req.session.authenticated)) {
res.render('authorization/login.html', {
layout: false,
'title': 'CUCM 2.0',
status: 403
});
return;
}
next();
}
// EXPRESS ROUTING - INDEX
app.get('/', function(req, res) {
res.render('index.html', {
layout: false,
'title': 'CUCM 2.0'
});
})
// EXPRESS ROUTING - INCLUDE - Extensions DB app routes
// var routingextensions = require('./routes/extensions.js')(app);
// INCLUDE - Extensions-admin DB app routes
// var routingextensions = require('./routes/extensions-admin.js')(app);
// EXPRESS ROUTING - INCLUDE - LMS DB app routes
// var routingextensions = require('./routes/lms.js')(app);
// EXPRESS ROUTING - INCLUDE - LMS-admin DB app routes
// var routingextensions = require('./routes/lms-admin.js')(app);
// EXPRESS ROUTING - INCLUDE - Authorization app routes
// var routingextensions = require('./routes/authorization.js')(app);
// SERVER - SETUP AND RUN
http.createServer(app).listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});