Skip to content

Instantly share code, notes, and snippets.

@NickNaso
Forked from adrai/app.js
Created July 5, 2017 22:12
Show Gist options
  • Save NickNaso/e3bca52cbcf4a9cfd286e01e85daa969 to your computer and use it in GitHub Desktop.
Save NickNaso/e3bca52cbcf4a9cfd286e01e85daa969 to your computer and use it in GitHub Desktop.
aws-serverless-fastify
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;
}
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');
const server = awsServerlessExpress.createServer(app);
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
@demsey2
Copy link

demsey2 commented Jul 4, 2018

is this is used in production? any chance to know what's the overhead with "createServer"? how much slower is it?

@benMain
Copy link

benMain commented Jul 4, 2019

Check out my package for a clean implementation.
https://www.npmjs.com/package/aws-serverless-fastify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment