A Promise-based wrapper around Hapi.
Hapi has a number of hooks for configuring a server, some of which can be asynchronous. Hapi Wrapper uses Promises and simple functions which allow the different configuration steps to be composed together.
Hapi-Wrapper also includes Inert by default when you add routes configured to serve static resources from the ./public
folder.
To include in your project run:
npm install --save @matthewglover/hapi-wrapper
.
To create a server:
const {
createServer,
setConnection,
registerPlugins,
addRoutes,
startServer } = require('@matthewglover/hapi-wrapper');
const port = process.env.PORT || 4000;
createServer()
.then(setConnection({ port }))
.then(registerPlugins())
.then(addRoutes())
.then(startServer)
.then(server => console.log(`Server running at: ${server.info.uri}`))
.catch(err => console.log(err));