Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Hapi example (several deprecated functions) #216

Merged
merged 2 commits into from Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions examples/hapi/package.json
@@ -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
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();