forked from ryanmurakami/pizza-luvrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.js
84 lines (75 loc) · 1.75 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
77
78
79
80
81
82
83
84
const Cookie = require('@hapi/cookie')
const Good = require('@hapi/good')
const Handlebars = require('handlebars')
const Inert = require('@hapi/inert')
const Vision = require('@hapi/vision')
const GoodFile = require('./lib/good-file')
const mockData = require('./data/mock')
const goodOptions = {
reporters: {
file: [{
module: '@hapi/good-squeeze',
name: 'Squeeze',
args: [{ response: '*', request: '*', error: '*' }]
}, {
module: '@hapi/good-squeeze',
name: 'SafeJson'
}, {
module: GoodFile,
args: ['./log/hapi_log']
}]
}
}
module.exports.register = async server => {
// register plugins
await server.register([
Inert,
Vision,
Cookie,
{
plugin: Good,
options: goodOptions
}
])
// setup template rendering
server.views({
engines: {
hbs: Handlebars
},
layout: true,
relativeTo: __dirname,
path: './templates',
partialsPath: './templates/partials',
helpersPath: './templates/helpers'
})
// setup cache
const cache = server.cache({
segment: 'sessions',
expiresIn: 24 * 60 * 60 * 1000
})
server.app.cache = cache
// setup authentication/session handling
const redirectPath = '/login'
server.auth.strategy('session', 'cookie', {
cookie: {
isSecure: false,
name: 'pzz4lyfe',
password: 'password-should-be-32-characters'
},
redirectTo: redirectPath,
appendNext: true,
validateFunc: async (request, session) => {
const cached = await cache.get(session.sid)
if (!cached) {
return { valid: false }
}
return {
credentials: cached.account,
valid: true
}
}
})
server.auth.default('session')
// setup data
mockData.hydrate()
}