Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SIGTERM handling for node templates #281

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions template/node12-debian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
Expand Down Expand Up @@ -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);
};
Expand Down
13 changes: 9 additions & 4 deletions template/node12/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -75,7 +75,7 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
Expand Down Expand Up @@ -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')
})
})
12 changes: 9 additions & 3 deletions template/node14/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -75,7 +75,7 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
Expand Down Expand Up @@ -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')
})
})

13 changes: 10 additions & 3 deletions template/node16/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -75,7 +75,7 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
Expand Down Expand Up @@ -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')
})
})


12 changes: 9 additions & 3 deletions template/node17/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -75,7 +75,7 @@ class FunctionContext {
}

this.headerValues = value;
return this;
return this;
}

succeed(value) {
Expand Down Expand Up @@ -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')
})
})