forked from ryanmurakami/pizza-luvrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.js
76 lines (66 loc) · 1.67 KB
/
plugins.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
'use strict';
let goodOptions = {
reporters: {
file: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ response: '*', request: '*', error: '*' }]
}, {
module: 'good-squeeze',
name: 'SafeJson'
}, {
module: 'good-file',
args: ['./log/hapi_log']
}]
}
};
module.exports.registerPlugins = (server, callback) => {
server.register([
{ register: require('inert') },
{ register: require('vision') },
{ register: require('hapi-auth-cookie') },
{
register: require('good'),
options: goodOptions
}
], (err) => {
if (err) callback(err);
server.views({
engines: {
hbs: require('handlebars')
},
layout: true,
relativeTo: __dirname,
path: './templates',
partialsPath: './templates/partials',
helpersPath: './templates/helpers'
});
const cache = server.cache({
segment: 'sessions',
expiresIn: 24 * 60 * 60 * 1000
});
server.app.cache = cache;
const redirectPath = '/login';
server.auth.strategy('session', 'cookie', true, {
password: 'password-should-be-32-characters',
cookie: 'pzz4lyfe',
redirectTo: redirectPath,
appendNext: true,
isSecure: false,
validateFunc: (request, session, callback) => {
cache.get(session.sid, (err, cached) => {
if (err) {
return callback(err, false);
}
if (!cached) {
return callback(null, false);
}
return callback(null, true, cached.account);
});
}
});
// setup data
// require('./data/mock.js').insertData();
callback();
});
};