Last active
August 29, 2015 14:23
-
-
Save poeticninja/9e8b2e81c20c9e39bf56 to your computer and use it in GitHub Desktop.
Base hapi server with logging.
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'); | |
var Good = require('good'); | |
var GoodConsole = require('good-console'); | |
var Boom = require('boom'); | |
var Joi = require('joi'); | |
// Create a new server | |
var server = new Hapi.Server(); | |
// Setup the server with a host and port | |
server.connection({ | |
port: parseInt(process.env.PORT, 10) || 3000, | |
host: '0.0.0.0', | |
router: { | |
stripTrailingSlash: true | |
} | |
}); | |
server.route({ | |
method: 'GET', | |
path: '/{path}', | |
config: { | |
handler: function(request, reply){ | |
reply(Boom.notFound()); | |
} | |
} | |
}); | |
/* | |
Load all plugins and then start the server. | |
First: community/npm plugins are loaded | |
Second: project specific plugins are loaded | |
*/ | |
server.register([ | |
{ | |
register: Good, | |
options: { | |
reporters: [{ | |
reporter: GoodConsole, | |
events: { ops: '*', request: '*', log: '*', response: '*', 'error': '*' } | |
}] | |
} | |
} | |
], function () { | |
//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