diff --git a/fastify-app-lambda/app.js b/fastify-app-lambda/app.js index 8589590..a5b2a30 100644 --- a/fastify-app-lambda/app.js +++ b/fastify-app-lambda/app.js @@ -1,15 +1,18 @@ const fastify = require('fastify'); -const app = fastify(); -app.get('/', (request, reply) => reply.send({ hello: 'world' })); +function init() { + const app = fastify(); + app.get('/', (request, reply) => reply.send({ hello: 'world' })); + return app; +} -if (require.main !== module) { +if (require.main === module) { // called directly i.e. "node app" - app.listen(3000, (err) => { + init().listen(3000, (err) => { if (err) console.error(err); console.log('server listening on 3000'); }); } else { // required as a module => executed on aws lambda - module.exports = app; -} \ No newline at end of file + module.exports = init; +}