/
server.js
executable file
·58 lines (45 loc) · 1.05 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
'use strict';
const Crumb = require('..');
const Hapi = require('@hapi/hapi');
const Vision = require('@hapi/vision');
const server = Hapi.server({
host: '127.0.0.1',
port: 8000
});
const plugins = [
Vision,
{
plugin: Crumb,
options: {
cookieOptions: {
isSecure: false
}
}
}
];
(async () => {
await server.register(plugins);
server.views({
relativeTo: __dirname,
path: 'templates',
engines: {
html: require('handlebars')
}
});
server.route({
method: 'get',
path: '/',
handler: function (request, h) {
return h.view('index', { title: 'test', message: 'hi' });
}
});
server.route({
method: 'post',
path: '/',
handler: function (request, h) {
return h.view('message', { title: 'test', message: request.payload.message });
}
});
await server.start();
console.log('Example server running at:', server.info.uri);
})();