mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Graceful shutdown on SIGINT (e.g. from 'pm2 stop').
(cherry picked from commit 6709c3bb5f
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
a37e0f29b7
commit
15c2af5fbf
23
server.ts
23
server.ts
@@ -32,6 +32,7 @@ import isbot from 'isbot';
|
||||
import { createCertificate } from 'pem';
|
||||
import { createServer } from 'https';
|
||||
import { json } from 'body-parser';
|
||||
import { createHttpTerminator } from 'http-terminator';
|
||||
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
@@ -488,7 +489,7 @@ function saveToCache(req, page: any) {
|
||||
*/
|
||||
function hasNotSucceeded(statusCode) {
|
||||
const rgx = new RegExp(/^20+/);
|
||||
return !rgx.test(statusCode)
|
||||
return !rgx.test(statusCode);
|
||||
}
|
||||
|
||||
function retrieveHeaders(response) {
|
||||
@@ -526,12 +527,20 @@ function serverStarted() {
|
||||
* @param keys SSL credentials
|
||||
*/
|
||||
function createHttpsServer(keys) {
|
||||
createServer({
|
||||
const listener = createServer({
|
||||
key: keys.serviceKey,
|
||||
cert: keys.certificate
|
||||
}, app).listen(environment.ui.port, environment.ui.host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
|
||||
// Graceful shutdown when signalled
|
||||
const terminator = createHttpTerminator({server: listener});
|
||||
process.on('SIGINT', ()=> {
|
||||
console.debug('Closing HTTPS server on signal');
|
||||
terminator.terminate().catch(e => { console.error(e); });
|
||||
console.debug('HTTPS server closed');
|
||||
});
|
||||
}
|
||||
|
||||
function run() {
|
||||
@@ -540,9 +549,17 @@ function run() {
|
||||
|
||||
// Start up the Node server
|
||||
const server = app();
|
||||
server.listen(port, host, () => {
|
||||
const listener = server.listen(port, host, () => {
|
||||
serverStarted();
|
||||
});
|
||||
|
||||
// Graceful shutdown when signalled
|
||||
const terminator = createHttpTerminator({server: listener});
|
||||
process.on('SIGINT', ()=> {
|
||||
console.debug('Closing HTTP server on signal');
|
||||
terminator.terminate().catch(e => { console.error(e); });
|
||||
console.debug('HTTP server closed.');
|
||||
});
|
||||
}
|
||||
|
||||
function start() {
|
||||
|
Reference in New Issue
Block a user