Skip to content

Instantly share code, notes, and snippets.

@geek
Last active August 29, 2015 14:10
Show Gist options
  • Save geek/287189574c6adf2ec7ff to your computer and use it in GitHub Desktop.
Save geek/287189574c6adf2ec7ff to your computer and use it in GitHub Desktop.

Connection after route

var Hapi = require('hapi');

var server = new Hapi.Server();

server.route({ method: 'get', path: '/hello', handler: function (request, reply) {

    reply('World');
}});

server.connection();
server.inject({ method: 'get', url: '/hello' }, function (res) {

    console.log(res.result);
});

Output:

{ statusCode: 404, error: 'Not Found' }

Connection before route

var Hapi = require('hapi');

var server = new Hapi.Server();
server.connection();

server.route({ method: 'get', path: '/hello', handler: function (request, reply) {

    reply('World');
}});


server.inject({ method: 'get', url: '/hello' }, function (res) {

    console.log(res.result);
});

Output:

World
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment