-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
75 lines (67 loc) · 1.28 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
'use strict';
const Hapi = require('hapi');
const inert = require('inert');
const Good = require('good');
const socket = require('./server/socket');
const HOST = process.env.HOSTNAME;
const PORT = process.env.NODE_PORT;
// Create a server with a host and port
const server = new Hapi.Server();
server.connection({
host: HOST,
port: PORT
});
server.register({
register: Good,
options: {
reporters: {
console: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{
response: '*',
log: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
}
}
}, (err) => {
if (err) {
console.log('OH NO Good module is broken', err); // something bad happened loading the plugin
}
});
server.register(inert, (err) => {
if (err) {
throw err;
}
});
server.route({
method: 'GET',
path: '/',
handler: (request, reply) => reply.file('./public/index.html')
});
server.route({
method: 'GET',
path: '/comments',
handler: socket.load
});
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'public'
}
}
});
// Start the server
server.start((err) => {
if (err) {
console.log('OH NO server not started', err);
}
socket.init(server.listener, () => {
console.log(`socket.io listening on http://127.0.0.1:${PORT}`);
});
});