Extract 'served-by-host-header' middleware and move it to api router
This commit is contained in:
parent
1bb1a350e0
commit
79143e3df6
@ -18,6 +18,8 @@ const CopyController = require('./copy_controller');
|
||||
const JobController = require('./job_controller');
|
||||
|
||||
const cors = require('../middlewares/cors');
|
||||
const servedByHostHeader = require('../middlewares/served-by-host-header');
|
||||
|
||||
|
||||
module.exports = class ApiRouter {
|
||||
constructor ({ redisPool, metadataBackend, statsClient, dataIngestionLogger }) {
|
||||
@ -64,6 +66,7 @@ module.exports = class ApiRouter {
|
||||
const apiRouter = router({ mergeParams: true });
|
||||
|
||||
apiRouter.use(cors());
|
||||
apiRouter.use(servedByHostHeader());
|
||||
|
||||
this.queryController.route(apiRouter);
|
||||
this.copyController.route(apiRouter);
|
||||
|
13
app/middlewares/served-by-host-header.js
Normal file
13
app/middlewares/served-by-host-header.js
Normal file
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
|
||||
module.exports = function servedByHostHeader () {
|
||||
const hostname = global.settings.api_hostname || os.hostname().split('.')[0];
|
||||
|
||||
return function servedByHostHeaderMiddleware (req, res, next) {
|
||||
res.set('X-Served-By-Host', hostname);
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
@ -95,10 +95,6 @@ function App(statsClient) {
|
||||
app.use(function bootstrap$prepareRequestResponse(req, res, next) {
|
||||
res.locals = res.locals || {};
|
||||
|
||||
if (global.settings.api_hostname) {
|
||||
res.header('X-Served-By-Host', global.settings.api_hostname);
|
||||
}
|
||||
|
||||
var profile = global.settings.useProfiler;
|
||||
req.profiler = new Profiler({
|
||||
profile: profile,
|
||||
|
Loading…
Reference in New Issue
Block a user