Skip to content

Commit 61bba46

Browse files
authored
Merge pull request #216 from CodisRedding/master
update Hapi example (several deprecated functions)
2 parents a0178fa + 45a0216 commit 61bba46

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

examples/hapi/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "sockjs-hapi",
3-
"version": "0.0.0-unreleasable",
4-
"dependencies": {
5-
"hapi": "*",
6-
"sockjs": "*"
7-
}
2+
"name": "sockjs-hapi",
3+
"version": "0.0.0-unreleasable",
4+
"dependencies": {
5+
"hapi": "15.x.x",
6+
"inert": "4.x.x",
7+
"sockjs": "*"
8+
}
89
}

examples/hapi/server.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ var sockjs = require('sockjs');
66
var Hapi = require('hapi');
77

88
// 1. Echo sockjs server
9-
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
9+
var sockjs_opts = {
10+
sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"
11+
};
1012

1113
var sockjs_echo = sockjs.createServer(sockjs_opts);
1214
sockjs_echo.on('connection', function(conn) {
@@ -15,19 +17,26 @@ sockjs_echo.on('connection', function(conn) {
1517
});
1618
});
1719

18-
// Create a server with a host and port
19-
var hapi_server = Hapi.createServer('0.0.0.0', 9999);
20+
// Create a server and set port (default host 0.0.0.0)
21+
var hapi_server = new Hapi.Server();
22+
hapi_server.connection({
23+
port: 9999
24+
});
2025

21-
hapi_server.route({
22-
method: 'GET',
23-
path: '/{path*}',
24-
handler: {
25-
directory: { path: './html', listing: false, index: true }
26-
}
26+
hapi_server.register(require('inert'), (err) => {
27+
hapi_server.route({
28+
method: 'GET',
29+
path: '/{path*}',
30+
handler: function(request, reply) {
31+
reply.file('./html/index.html');
32+
}
33+
});
2734
});
2835

2936
//hapi_server.listener is the http listener hapi uses
30-
sockjs_echo.installHandlers(hapi_server.listener, {prefix:'/echo'});
37+
sockjs_echo.installHandlers(hapi_server.listener, {
38+
prefix: '/echo'
39+
});
3140

32-
console.log(' [*] Listening on 0.0.0.0:9999' );
41+
console.log(' [*] Listening on 0.0.0.0:9999');
3342
hapi_server.start();

0 commit comments

Comments
 (0)