-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
58 lines (49 loc) · 1.99 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
var path = require('path'),
hapi = require('hapi'),
good = require('good'),
server = new hapi.Server(3000),
routes = require('./server/routes'),
db = require('./server/services/db');
console.log('Attempting to connect to MongoDB via Mongoose...');
db.connect(function(valid) {
if(valid) {
console.log('Successfully connected to MongoDB via Mongoose!');
// Application setup
var argv = require('minimist')(process.argv.slice(2));
if(argv['force-setup']) {
require('shelljs/global');
console.log('--force-setup flag detected, dropping server-dash database and running setup script.');
exec('mongo server-dash --eval "db.dropDatabase()"');
}
var setup = require('./setup/setup.js');
setup.userSetup(function() {
setup.widgetSetup(function() {
// Setup server
server.pack.register([good, require('hapi-auth-cookie')], function(err) {
if(err) {
throw err; // plugin failed
}
server.auth.strategy('session', 'cookie', {
password: 'Th!sAppR0cks!', // cookie secret
cookie: '_serverDashAuth', // cookie name
redirectTo: false,
isSecure: false,
ttl: 1000 * 60 * 60 * 24
});
routes.registerRoutes(server);
server.views({
engines: {
html: require('handlebars')
},
path: path.join(__dirname, 'server/views')
});
server.start(function() {
server.log('info', 'Server running at: ' + server.info.uri);
});
});
});
});
} else {
console.error('Error in Mongoose connection.');
}
});