-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
41 lines (32 loc) · 786 Bytes
/
app.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
'use strict';
var Hapi = require('hapi');
var path = require('path');
var server = new Hapi.Server();
server.connection({ port: 3000 });
var io = require('socket.io')(server.listener);
// set view engine to handlebars
server.views({
engines: {
html: require('handlebars')
},
path: path.join(__dirname, 'templates')
});
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply.view('index.html');
}
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
server.start(function() {
console.log('Server running at:', server.info.uri);
});