-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (66 loc) · 1.35 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
64
65
66
67
68
69
70
71
72
73
74
75
// Dependencies
var Boom = require('boom');
var Joi = require('joi');
var Path = require('path');
var Hapi = require('hapi');
var Vision = require('vision');
var Inert = require('inert');
// Template Engine
var Handlerbars = require('handlebars');
var HandlebarsLayouts = require('handlebars-layouts');
HandlebarsLayouts.register(Handlerbars);
// HTTP Server
var server = Hapi.server({
port: 8000,
routes: {
cors: {
credentials: true
}
}
});
// HTTP Server Initialization Configuration
var initialization = async function() {
// Register modules
await server.register(Vision);
await server.register(Inert);
// Setup view rendering
server.views({
engines: {
html: {
module: Handlerbars
}
},
relativeTo: Path.join(__dirname, 'public'),
path: './views',
partialsPath: './views'
});
// Base HTTP route
server.route({
method: 'GET',
path: '/',
handler: function(request, reply)
{
return reply.view('base', {});
}
});
// Handles public file routing
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'public',
listing: true
}
}
});
// Attempt to start the HTTP Server
try {
await server.start();
}
catch (err) {
process.exit(1);
}
};
// Initilize HTTP Server
initialization();