-
Notifications
You must be signed in to change notification settings - Fork 129
/
server.js
64 lines (53 loc) · 1.43 KB
/
server.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
var Hapi = require('hapi'),
config = require('./config.js')
var server = new Hapi.Server(config.host, config.port, config.server)
server.route({
path: '/favicon.ico',
method: 'GET',
handler: { file: './favicon.ico' }
})
server.route({
path: '/static/{path*}',
method: 'GET',
handler: {
directory: {
path: './static',
listing: false,
index: false
}
}
});
server.pack.require({
'hapi-auth-cookie': null,
'./facets/company': null,
'./facets/registry': null,
'./facets/user': config.user,
'./services/hapi-couchdb': config.couch
}, function(err) {
if (err) throw err;
var cache = server.cache('sessions', {
expiresIn: config.session.expiresIn
});
server.app.cache = cache;
server.auth.strategy('session', 'cookie', 'try', {
password: config.session.password,
cookie: config.session.cookie,
redirectTo: '/login',
appendNext: true,
validateFunc: function (session, callback) {
cache.get(session.sid, function (err, cached) {
// use this spot here to verify user is still logged into couch
if (err) {
return callback(err, false);
}
if (!cached) {
return callback(null, false);
}
return callback(null, true, cached.item)
})
}
});
server.start(function() {
console.log('Hapi server started @ ' + server.info.uri);
});
});