-
-
Save NickNaso/e3bca52cbcf4a9cfd286e01e85daa969 to your computer and use it in GitHub Desktop.
aws-serverless-fastify
This file contains hidden or 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
const fastify = require('fastify')(); | |
fastify.get('/', (request, reply) => reply.send({ hello: 'world' })); | |
if (require.main === module) { | |
// called directly i.e. "node app" | |
fastify.listen(3000, (err) => { | |
if (err) console.error(err); | |
console.log(`server listening on ${fastify.server.address().port}`); | |
}); | |
} else { | |
// required as a module => executed on aws lambda | |
module.exports = fastify; | |
} |
This file contains hidden or 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
const awsServerlessExpress = require('aws-serverless-express'); | |
const app = require('./app'); | |
const server = awsServerlessExpress.createServer(app); | |
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out my package for a clean implementation.
https://www.npmjs.com/package/aws-serverless-fastify