-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (34 loc) · 1.3 KB
/
index.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
var express = require('express');
var app = express();
var session = require('express-session');
var bodyParser = require('body-parser');
var utils = require('./helpers/utils');
var dbHelper = require('./helpers/dbHelper');
var Routes = require('./routes/routes');
var staticDir = __dirname + '/public';
app.set('db-uri', 'mongodb://localhost:27017/localisation');
app.use(express.static(staticDir));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 50000 }));
app.use(bodyParser.json({limit: '50mb', parameterLimit: 5000}));
app.use(session({secret: 'localisation secret', resave: true, saveUninitialized: true}));
app.set('views', staticDir);
app.set('view engine', 'jade');
dbHelper.initialize(app.get('db-uri'));
(function decorateLog() {
var originalLog = console.log;
console.log = function(log) {
var date = new Date();
var text = '[' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds() + '] ' + log;
originalLog(text);
}
})();
var routes = new Routes(app);
app.get('/', utils.checkAuth, function(req, res) {
var user = req.session.auth;
res.render('index.jade', {user: user, key: utils.currentKey()});
});
app.get('/accounts', utils.isAdmin, function(req, res) {
res.render('users.jade');
});
app.post('/newkey', utils.changeCurrentKey);
app.listen(3000);