Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions fastify-app-lambda/app.js
Original file line number Diff line number Diff line change
@@ -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;
}
module.exports = init;
}