diff --git a/template/node12-debian/index.js b/template/node12-debian/index.js index b1137687..6aa48bae 100644 --- a/template/node12-debian/index.js +++ b/template/node12-debian/index.js @@ -53,7 +53,7 @@ class FunctionContext { } this.headerValues = value; - return this; + return this; } succeed(value) { @@ -107,10 +107,17 @@ app.options('/*', middleware); const port = process.env.http_port || 3000; -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`OpenFaaS Node.js listening on port: ${port}`) }); +process.on('SIGTERM', () => { + console.log('SIGTERM signal received: closing HTTP server') + server.close(() => { + console.log('HTTP server closed') + }) +}) + let isArray = (a) => { return (!!a) && (a.constructor === Array); }; diff --git a/template/node12/index.js b/template/node12/index.js index 99e59220..4222696f 100644 --- a/template/node12/index.js +++ b/template/node12/index.js @@ -17,7 +17,7 @@ const rawLimit = process.env.MAX_RAW_SIZE || defaultMaxSize const jsonLimit = process.env.MAX_JSON_SIZE || defaultMaxSize app.use(function addDefaultContentType(req, res, next) { - // When no content-type is given, the body element is set to + // When no content-type is given, the body element is set to // nil, and has been a source of contention for new users. if(!req.headers['content-type']) { @@ -75,7 +75,7 @@ class FunctionContext { } this.headerValues = value; - return this; + return this; } succeed(value) { @@ -137,8 +137,13 @@ app.options('/*', middleware); const port = process.env.http_port || 3000; -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`node12 listening on port: ${port}`) }); - +process.on('SIGTERM', () => { + console.log('SIGTERM signal received: closing HTTP server') + server.close(() => { + console.log('HTTP server closed') + }) +}) diff --git a/template/node14/index.js b/template/node14/index.js index b67e5ede..62abf8e5 100644 --- a/template/node14/index.js +++ b/template/node14/index.js @@ -17,7 +17,7 @@ const rawLimit = process.env.MAX_RAW_SIZE || defaultMaxSize const jsonLimit = process.env.MAX_JSON_SIZE || defaultMaxSize app.use(function addDefaultContentType(req, res, next) { - // When no content-type is given, the body element is set to + // When no content-type is given, the body element is set to // nil, and has been a source of contention for new users. if(!req.headers['content-type']) { @@ -75,7 +75,7 @@ class FunctionContext { } this.headerValues = value; - return this; + return this; } succeed(value) { @@ -137,8 +137,14 @@ app.options('/*', middleware); const port = process.env.http_port || 3000; -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`node14 listening on port: ${port}`) }); +process.on('SIGTERM', () => { + console.log('SIGTERM signal received: closing HTTP server') + server.close(() => { + console.log('HTTP server closed') + }) +}) diff --git a/template/node16/index.js b/template/node16/index.js index b67e5ede..1097e115 100644 --- a/template/node16/index.js +++ b/template/node16/index.js @@ -17,7 +17,7 @@ const rawLimit = process.env.MAX_RAW_SIZE || defaultMaxSize const jsonLimit = process.env.MAX_JSON_SIZE || defaultMaxSize app.use(function addDefaultContentType(req, res, next) { - // When no content-type is given, the body element is set to + // When no content-type is given, the body element is set to // nil, and has been a source of contention for new users. if(!req.headers['content-type']) { @@ -75,7 +75,7 @@ class FunctionContext { } this.headerValues = value; - return this; + return this; } succeed(value) { @@ -137,8 +137,15 @@ app.options('/*', middleware); const port = process.env.http_port || 3000; -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`node14 listening on port: ${port}`) }); +process.on('SIGTERM', () => { + console.log('SIGTERM signal received: closing HTTP server') + server.close(() => { + console.log('HTTP server closed') + }) +}) + diff --git a/template/node17/index.js b/template/node17/index.js index b67e5ede..62abf8e5 100644 --- a/template/node17/index.js +++ b/template/node17/index.js @@ -17,7 +17,7 @@ const rawLimit = process.env.MAX_RAW_SIZE || defaultMaxSize const jsonLimit = process.env.MAX_JSON_SIZE || defaultMaxSize app.use(function addDefaultContentType(req, res, next) { - // When no content-type is given, the body element is set to + // When no content-type is given, the body element is set to // nil, and has been a source of contention for new users. if(!req.headers['content-type']) { @@ -75,7 +75,7 @@ class FunctionContext { } this.headerValues = value; - return this; + return this; } succeed(value) { @@ -137,8 +137,14 @@ app.options('/*', middleware); const port = process.env.http_port || 3000; -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`node14 listening on port: ${port}`) }); +process.on('SIGTERM', () => { + console.log('SIGTERM signal received: closing HTTP server') + server.close(() => { + console.log('HTTP server closed') + }) +})