-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (54 loc) · 1.33 KB
/
server.js
File metadata and controls
63 lines (54 loc) · 1.33 KB
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
// Create a basic Hapi.js server
require('babel-register')({
presets: ['es2015', 'react'],
});
var Hapi = require('hapi');
var dateFormat = require('dateformat');
var format = "dd mmm HH:MM:ss";
// Basic Hapi.js connection stuff
var server = new Hapi.Server();
server.connection({
host: '0.0.0.0',
port: 8000
});
// Register the inert and vision Hapi plugins
// As of Hapi 9.x, these two plugins are no longer
// included in Hapi automatically
// https://github.com/hapijs/hapi/issues/2682
server.register([{
register: require('inert')
}, {
register: require('vision')
}], function(err) {
if (err) return console.error(err);
// Add the React-rendering view engine
server.views({
engines: {
jsx: require('hapi-react-views')
},
relativeTo: __dirname,
path: 'views'
});
// Add a route to serve static assets (CSS, JS, IMG)
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'assets',
index: ['index.html']
}
}
});
// Add main app route
server.route({
method: 'GET',
path: '/',
handler: {
view: 'Default'
}
});
server.start(function() {
console.log(dateFormat(new Date(), format) + ' - Server started at: ' + server.info.uri);
});
});