Extract socket timeout middleware
This commit is contained in:
parent
f9c467a628
commit
c60a44252d
@ -17,10 +17,11 @@ const QueryController = require('./query_controller');
|
||||
const CopyController = require('./copy_controller');
|
||||
const JobController = require('./job_controller');
|
||||
|
||||
const cors = require('../middlewares/cors');
|
||||
const servedByHostHeader = require('../middlewares/served-by-host-header');
|
||||
const socketTimeout = require('../middlewares/socket-timeout');
|
||||
const logger = require('../middlewares/logger');
|
||||
const profiler = require('../middlewares/profiler');
|
||||
const cors = require('../middlewares/cors');
|
||||
const servedByHostHeader = require('../middlewares/served-by-host-header');
|
||||
|
||||
module.exports = class ApiRouter {
|
||||
constructor ({ redisPool, metadataBackend, statsClient, dataIngestionLogger }) {
|
||||
@ -68,6 +69,7 @@ module.exports = class ApiRouter {
|
||||
route (app) {
|
||||
const apiRouter = router({ mergeParams: true });
|
||||
|
||||
apiRouter.use(socketTimeout());
|
||||
apiRouter.use(logger());
|
||||
apiRouter.use(profiler({ statsClient: this.statsClient }));
|
||||
apiRouter.use(cors());
|
||||
|
18
app/middlewares/socket-timeout.js
Normal file
18
app/middlewares/socket-timeout.js
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function socketTimeout () {
|
||||
if (!global.settings.hasOwnProperty('node_socket_timeout')) {
|
||||
return function dummySocketTimeoutMiddleware (req, res, next) {
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
||||
const timeout = parseInt(global.settings.node_socket_timeout);
|
||||
|
||||
return function socketTimeoutMiddleware (req, res, next) {
|
||||
// Set connection timeout
|
||||
req.connection.setTimeout(timeout);
|
||||
|
||||
next();
|
||||
}
|
||||
}
|
@ -74,15 +74,6 @@ function App(statsClient) {
|
||||
mkdirp.sync(global.settings.tmpDir);
|
||||
}
|
||||
|
||||
// Set connection timeout
|
||||
if (global.settings.hasOwnProperty('node_socket_timeout')) {
|
||||
var timeout = parseInt(global.settings.node_socket_timeout);
|
||||
app.use(function(req, res, next) {
|
||||
req.connection.setTimeout(timeout);
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
app.enable('jsonp callback');
|
||||
app.set("trust proxy", true);
|
||||
app.disable('x-powered-by');
|
||||
|
Loading…
Reference in New Issue
Block a user