-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (66 loc) · 2.06 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
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
var basicStrategy = require('./lib/basic-strategy'),
db = require('./lib/database'),
express = require('express'),
exphbs = require('express-handlebars'),
http = require('http'),
kraken = require('kraken-js'),
passport = require('passport');
var options, app, server, hbs;
/*
* Create and configure application. Also exports application instance for use by tests.
* See https://github.com/krakenjs/kraken-js#options for additional configuration options.
*/
options = {
onconfig: function (config, next) {
/*
* Add any additional config setup or overrides here. `config` is an initialized
* `confit` (https://github.com/krakenjs/confit/) configuration object.
*/
db.config(config.get('databaseConfig'));
next(null, config);
}
};
hbs = exphbs.create({
extname: '.hbs',
defaultLayout: 'main',
helpers: {
group: function (index, opts) {
if (index % 2 === 0 && index !== 0) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
}
}
});
app = module.exports = express();
app.use(kraken(options));
passport.use(basicStrategy);
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
});
app.use(passport.initialize());
app.use(passport.session());
app.engine('hbs', hbs.engine);
app.on('start', function () {
console.log('Application ready to serve requests.');
console.log('Environment: %s', app.kraken.get('env:env'));
});
/*
* Create and start HTTP server.
*/
if (!module.parent) {
/*
* This is only done when this module is run directly, e.g. `node .` to allow for the
* application to be used in tests without binding to a port or file descriptor.
*/
server = http.createServer(app);
server.listen(process.env.PORT || 8000);
server.on('listening', function () {
console.log('Server listening on http://localhost:%d', this.address().port);
});
}