Extract middleware served by host header

This commit is contained in:
Daniel García Aubert
2018-03-26 19:53:33 +02:00
parent 59db640d0d
commit cb488cbde8
3 changed files with 13 additions and 9 deletions
@@ -0,0 +1,11 @@
const os = require('os');
module.exports = function servedByHostHeader () {
const hostname = os.hostname().split('.')[0];
return function servedByHostHeaderMiddleware (req, res, next) {
res.set('X-Served-By-Host', hostname);
next();
};
};
+2 -7
View File
@@ -50,6 +50,7 @@ var StatsBackend = require('./backends/stats');
const lzmaMiddleware = require('./middleware/lzma');
const errorMiddleware = require('./middleware/error-middleware');
const servedByHostHeader = require('./middleware/served-by-host-header');
module.exports = function(serverOptions) {
// Make stats client globally accessible
@@ -364,13 +365,7 @@ function bootstrap(opts) {
app.use(bodyParser.json());
app.use(function bootstrap$prepareRequestResponse(req, res, next) {
if (global.environment && global.environment.api_hostname) {
res.set('X-Served-By-Host', global.environment.api_hostname);
}
next();
});
app.use(servedByHostHeader());
app.use(stats({
enabled: opts.useProfiler,