Deploy powerful, scalable applications, using hapi on top of AWS Lambda and Amazon API Gateway.
hapi-front turns your regular hapi server into a serverless function, easily deployable on AWS.
It does so using a translation layer between AWS requests, and regular HTTP requests sent into your hapi server.
Inspired by serverless-http. Tailored for hapi.
- Code regular hapi servers, deploy as serverless 🚀
- Single command deployment
- No external dependencies
yarn add hapi-front
or
npm install hapi-front --save
Wrap your current server initialization code with hapi-front
:
// server.js
module.exports = async () => {
const server = Hapi.server({
port: process.env.port || 3000,
host: 'localhost'
})
// define routes here
return server
}
// index.js
const front = require('hapi-front')
const init = require('./server')
module.exports.handler = front(init)
See example folder for a full example that uses the Serverless Framework.
Use serverless-offline
plugin to run locally:
serverless offline
Or, simply create a wrapper around server.js
to run as a rugaulr hapi server:
const init = require('./server')
let server
const go = async () => {
server = await init()
await server.start()
console.log(`Server ready on ${server.info.uri}`)
}
go()
.then(console.log)
.catch(console.log)
To deploy:
serverless deploy