Skip to content
Draft
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
21 changes: 19 additions & 2 deletions template/node18/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const express = require('express')
const app = express()
const handler = require('./function/handler');
const bodyParser = require('body-parser')
const bodyParser = require('body-parser');

const defaultMaxSize = '100kb' // body-parser default

Expand Down Expand Up @@ -137,8 +137,25 @@ app.options('/*', middleware);

const port = process.env.http_port || 3000;

app.listen(port, () => {
const server = app.listen(port, () => {
console.log(`node18 listening on port: ${port}`)
});

const writeTimeout = process.env.write_timeout;

process.on('SIGTERM', async () => {
console.log(`Function got SIGTERM event, draining up to: ${writeTimeout}`);
await gracefulShutdown();
})

async function gracefulShutdown() {
await new Promise((resolve) => {
setTimeout(resolve, writeTimeout);
})

server.close(() => {
console.log('Server gracefully shut down');
process.exit(0);
});
}