From 9081d93b5331f338b3112e99ef2e0bb80b59fa44 Mon Sep 17 00:00:00 2001 From: Pavel Lang Date: Thu, 8 Feb 2018 04:21:37 +0100 Subject: [PATCH] Be more strict on unhandled promise rejections (#1536) --- src/server.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/server.js b/src/server.js index bd5164ac6..42272ea5d 100644 --- a/src/server.js +++ b/src/server.js @@ -31,13 +31,11 @@ import schema from './data/schema'; import assets from './assets.json'; // eslint-disable-line import/no-unresolved import config from './config'; -const app = express(); - -// -// If you are using proxy from external machine, you can set TRUST_PROXY env -// Default is to trust proxy headers only from loopback interface. -// ----------------------------------------------------------------------------- -app.set('trust proxy', config.trustProxy); +process.on('unhandledRejection', (reason, p) => { + console.error('Unhandled Rejection at:', p, 'reason:', reason); + // send entire app down. Process manager will restart it + process.exit(1); +}); // // Tell any CSS tooling (such as Material UI) to use all vendor prefixes if the @@ -46,6 +44,14 @@ app.set('trust proxy', config.trustProxy); global.navigator = global.navigator || {}; global.navigator.userAgent = global.navigator.userAgent || 'all'; +const app = express(); + +// +// If you are using proxy from external machine, you can set TRUST_PROXY env +// Default is to trust proxy headers only from loopback interface. +// ----------------------------------------------------------------------------- +app.set('trust proxy', config.trustProxy); + // // Register Node.js middleware // -----------------------------------------------------------------------------