-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·81 lines (63 loc) · 1.91 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
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var credentials = require('./credentials');
var session = require('express-session');
var bodyParser = require('body-parser');
var uri = 'mongodb://localhost/packagetracker';
mongoose.connect(uri);
var handlebars = require('express-handlebars').create({
defaultLayout: 'main',
helpers: {
section: function( name, options){
if(! this. _sections) this. _sections = {};
this. _sections[ name] = options.fn(this);
return null;
}
}
});
var app = express();
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
app.use(express.static(__dirname + '/public'));
app.use(cookieParser(credentials.cookieSecret));
app.use(session({
secret: credentials.cookieSecret,
saveUninitialized: true,
resave: true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(logger('combined'));
//This must go above the csurf injection because github doesn't use csrf tokens
app.use(require('./routes/ci'));
app.use(require('csurf')());
app.use(function(req, res, next) {
res.locals._csrfToken = req.csrfToken();
next();
});
app.use(function(req, res, next) {
res.locals.flash = req.session.flash;
delete req.session.flash;
next();
});
var auth = require('./lib/auth');
auth.initialize(app);
auth.registerRoutes(app);
app.use(require('./routes/index'));
app.use(require('./routes/user'));
app.use(require('./routes/package'));
app.use(function(req, res) {
res.status(404);
res.render('404');
});
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500);
res.render('500');
});
module.exports = app;