Skip to content

Commit

Permalink
Merge pull request #216 from CodisRedding/master
Browse files Browse the repository at this point in the history
update Hapi example (several deprecated functions)
  • Loading branch information
brycekahle authored Nov 3, 2016
2 parents a0178fa + 45a0216 commit 61bba46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
13 changes: 7 additions & 6 deletions examples/hapi/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "sockjs-hapi",
"version": "0.0.0-unreleasable",
"dependencies": {
"hapi": "*",
"sockjs": "*"
}
"name": "sockjs-hapi",
"version": "0.0.0-unreleasable",
"dependencies": {
"hapi": "15.x.x",
"inert": "4.x.x",
"sockjs": "*"
}
}
31 changes: 20 additions & 11 deletions examples/hapi/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ var sockjs = require('sockjs');
var Hapi = require('hapi');

// 1. Echo sockjs server
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
var sockjs_opts = {
sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"
};

var sockjs_echo = sockjs.createServer(sockjs_opts);
sockjs_echo.on('connection', function(conn) {
Expand All @@ -15,19 +17,26 @@ sockjs_echo.on('connection', function(conn) {
});
});

// Create a server with a host and port
var hapi_server = Hapi.createServer('0.0.0.0', 9999);
// Create a server and set port (default host 0.0.0.0)
var hapi_server = new Hapi.Server();
hapi_server.connection({
port: 9999
});

hapi_server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: { path: './html', listing: false, index: true }
}
hapi_server.register(require('inert'), (err) => {
hapi_server.route({
method: 'GET',
path: '/{path*}',
handler: function(request, reply) {
reply.file('./html/index.html');
}
});
});

//hapi_server.listener is the http listener hapi uses
sockjs_echo.installHandlers(hapi_server.listener, {prefix:'/echo'});
sockjs_echo.installHandlers(hapi_server.listener, {
prefix: '/echo'
});

console.log(' [*] Listening on 0.0.0.0:9999' );
console.log(' [*] Listening on 0.0.0.0:9999');
hapi_server.start();

0 comments on commit 61bba46

Please sign in to comment.