Created
July 8, 2014 14:34
-
-
Save poeticninja/716ad6ef3c44e8fdf36e to your computer and use it in GitHub Desktop.
Fast Hapi Server, Hapi and Good
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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