-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (47 loc) · 1.53 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
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
'use strict';
var kraken = require('kraken-js'),
db = require('./lib/database'),
auth = require('./lib/auth'),
User = require('./models/user'),
passport = require('passport'),
apiResponse = require('./lib/apiResponse'),
mailer = require('./lib/mailer'),
app = {};
app.configure = function configure(nconf, next) {
// Init database connection
// Takes config from config/app.json
db.config(nconf.get("mongodb"));
passport.use(auth.localStrategy());
//Give passport a way to serialize and deserialize a user. In this case, by the user's id.
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (id, done) {
User.findOne({_id: id}, function (err, user) {
done(null, user);
});
});
// Config mail helper
mailer.config(nconf.get("mail"));
next(null);
};
app.requestStart = function requestStart(server) {
// Run before most express middleware has been registered.
};
app.requestBeforeRoute = function requestBeforeRoute(server) {
// Run before any routes have been added.
server.use(apiResponse());
server.use(passport.initialize());
server.use(passport.session());
};
app.requestAfterRoute = function requestAfterRoute(server) {
// Run after all routes have been added.
};
if (require.main === module) {
kraken.create(app).listen(function (err) {
if (err) {
console.error(err.stack);
}
});
}
module.exports = app;