Skip to content

Commit fd53790

Browse files
committed
server: Configure TrustProxy via config files
1 parent f10f4d0 commit fd53790

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

server/config/config.default.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ let defaultConfig = {
9191
publicUrl:
9292
'This will be overriden by environment variable SERVER_PUBLIC_URL',
9393
},
94+
trustProxy: {
95+
enabled: false,
96+
// see https://expressjs.com/en/guide/behind-proxies.html
97+
value: 0,
98+
},
9499
};
95100

96101
module.exports = defaultConfig;

server/config/config.prod.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ let prodConfig = {
6262
},
6363
],
6464
},
65+
trustProxy: {
66+
enabled: true,
67+
// see https://expressjs.com/en/guide/behind-proxies.html
68+
value: 1,
69+
},
6570
};
6671

6772
prodConfig = _.merge({}, defaultConfig, prodConfig);

server/config/config.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ let testConfig = {
221221
},
222222
],
223223
},
224+
trustProxy: {
225+
enabled: false,
226+
// see https://expressjs.com/en/guide/behind-proxies.html
227+
value: 0,
228+
},
224229
};
225230

226231
testConfig = _.merge({}, defaultConfig, testConfig);

server/core/express.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ const constants = require('./constants');
1414
// App Setup
1515
const app = express();
1616

17-
if (config.rateLimit.enabled) {
18-
// As we are behind a nginx-proxy
19-
// see https://expressjs.com/en/guide/behind-proxies.html
20-
app.set('trust proxy', 1);
17+
if (config.trustProxy.enabled) {
18+
app.set('trust proxy', config.trustProxy.value);
2119
}
2220

2321
// Logger

server/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const displayConfigurationStatus = () => {
4949
console.log(chalk.gray(`[*] Helmet: ${config.helmet.enabled}`));
5050
console.log(chalk.gray(`[*] Morgan: ${config.morgan.enabled}`));
5151
console.log(chalk.gray(`[*] RateLimit: ${config.rateLimit.enabled}`));
52+
console.log(chalk.gray(`[*] TrustProxy: ${config.trustProxy.enabled}`));
5253
};
5354

5455
displayConfigurationStatus();

0 commit comments

Comments
 (0)