Skip to content

Instantly share code, notes, and snippets.

@poeticninja
Created July 8, 2014 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poeticninja/716ad6ef3c44e8fdf36e to your computer and use it in GitHub Desktop.
Save poeticninja/716ad6ef3c44e8fdf36e to your computer and use it in GitHub Desktop.
Fast Hapi Server, Hapi and Good
/**
* Dependencies.
*/
var hapi = require('hapi');
// Create a server with a host, port, and options
var server = hapi.createServer('0.0.0.0', parseInt(process.env.PORT, 10) || 3000);
server.pack.register([
{
plugin: require("good"),
options: {
subscribers: {
console: ['ops', 'request', 'log', 'error']
}
}
}
], function(err) {
if (err) throw err;
});
// Require the routes and pass the server object.
var routes = [
{
method: 'GET',
path: '/',
handler: function(request, reply){
reply('hello person!');
}
}
];
// Add the server routes
server.route(routes);
//Start the server
server.start(function() {
//Log to the console the host and port info
console.log('Server started at: ' + server.info.uri);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment