This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboot.js
86 lines (69 loc) · 2 KB
/
boot.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
// -- Module dependencies
var express = require('express'),
RedisStore = require('connect-redis')(express),
mongoose = require('mongoose'),
helpers = require('./helpers'),
gzippo = require('gzippo'),
settings = require('./conf/configuration').settings;
// -- Global paths
var views = __dirname + '/views',
static_root = __dirname + '/public',
docroot = process.cwd() + '/';
/**
* Express base configuration
* Bootstrap
*/
module.exports.boot = function(app) {
/**
* Global configuration
*/
app.configure(function() {
// -- Define view engine with its options
app.set('views', views);
app.set('view engine', 'jade');
// -- Parses x-www-form-urlencoded request bodies (and json)
app.use(express.bodyParser());
app.use(express.methodOverride());
// -- Cookie support
app.use(express.cookieParser());
// -- Set Redis Session
app.use(express.session({
secret: settings.sessionSecret,
store: new RedisStore({ maxAge: 300000 })
}));
// -- CRSF protection middleware
app.use(express.csrf());
// -- Stylus Middleware
app.use(require('stylus').middleware({
src: static_root,
dest: static_root,
compress: true,
warn: true
}));
// -- Express routing
app.use(app.router);
// -- Static ressources
app.use(express.staticCache());
var duration = 2592000000; // One month
app.use(gzippo.staticGzip(static_root, { maxAge: duration }));
app.use(express.favicon(static_root + '/favicon.ico'));
// -- 500 status
app.use(function(err, req, res, next) {
res.render('500', {
status: err.status || 500,
error: err
});
});
// -- 404 status
app.use(function(req, res, next) {
res.render('404', {
status: 404,
url: req.url
});
});
// -- Dynamic view helpers
app.dynamicHelpers(helpers.dynamicHelpers);
});
// -- Connect to appropriate MongoDB database
mongoose.connect(app.set('db-uri'));
};