Extract middleware served by host header
This commit is contained in:
parent
59db640d0d
commit
cb488cbde8
2
app.js
2
app.js
@ -100,8 +100,6 @@ if ( global.environment.log_filename ) {
|
|||||||
global.log4js.configure(log4jsConfig);
|
global.log4js.configure(log4jsConfig);
|
||||||
global.logger = global.log4js.getLogger();
|
global.logger = global.log4js.getLogger();
|
||||||
|
|
||||||
global.environment.api_hostname = require('os').hostname().split('.')[0];
|
|
||||||
|
|
||||||
// Include cartodb_windshaft only _after_ the "global" variable is set
|
// Include cartodb_windshaft only _after_ the "global" variable is set
|
||||||
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
|
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
|
||||||
var cartodbWindshaft = require('./lib/cartodb/server');
|
var cartodbWindshaft = require('./lib/cartodb/server');
|
||||||
|
11
lib/cartodb/middleware/served-by-host-header.js
Normal file
11
lib/cartodb/middleware/served-by-host-header.js
Normal file
@ -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();
|
||||||
|
};
|
||||||
|
};
|
@ -50,6 +50,7 @@ var StatsBackend = require('./backends/stats');
|
|||||||
|
|
||||||
const lzmaMiddleware = require('./middleware/lzma');
|
const lzmaMiddleware = require('./middleware/lzma');
|
||||||
const errorMiddleware = require('./middleware/error-middleware');
|
const errorMiddleware = require('./middleware/error-middleware');
|
||||||
|
const servedByHostHeader = require('./middleware/served-by-host-header');
|
||||||
|
|
||||||
module.exports = function(serverOptions) {
|
module.exports = function(serverOptions) {
|
||||||
// Make stats client globally accessible
|
// Make stats client globally accessible
|
||||||
@ -364,13 +365,7 @@ function bootstrap(opts) {
|
|||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
app.use(function bootstrap$prepareRequestResponse(req, res, next) {
|
app.use(servedByHostHeader());
|
||||||
if (global.environment && global.environment.api_hostname) {
|
|
||||||
res.set('X-Served-By-Host', global.environment.api_hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(stats({
|
app.use(stats({
|
||||||
enabled: opts.useProfiler,
|
enabled: opts.useProfiler,
|
||||||
|
Loading…
Reference in New Issue
Block a user