Set 404 as defautl status code and set the proper status code fir the response at very same time that the response body
This commit is contained in:
parent
9feea66550
commit
c51e254287
@ -40,6 +40,7 @@ const ResourceLocator = require('../models/resource-locator');
|
||||
const LayergroupMetadata = require('../utils/layergroup-metadata');
|
||||
const RendererStatsReporter = require('../stats/reporter/renderer');
|
||||
|
||||
const initializeStatusCode = require('./middlewares/initialize-status-code');
|
||||
const logger = require('./middlewares/logger');
|
||||
const bodyParser = require('body-parser');
|
||||
const servedByHostHeader = require('./middlewares/served-by-host-header');
|
||||
@ -193,6 +194,7 @@ module.exports = class ApiRouter {
|
||||
const apiRouter = router();
|
||||
|
||||
apiRouter.use(logger(this.serverOptions));
|
||||
apiRouter.use(initializeStatusCode());
|
||||
apiRouter.use(bodyParser.json());
|
||||
apiRouter.use(servedByHostHeader());
|
||||
apiRouter.use(stats({
|
||||
|
@ -99,6 +99,7 @@ function prepareResponse () {
|
||||
return -1;
|
||||
});
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = { catalog: analysisCatalog };
|
||||
|
||||
next();
|
||||
|
@ -48,6 +48,7 @@ function analysisNodeStatus (analysisStatusBackend) {
|
||||
'Last-Modified': new Date().toUTCString()
|
||||
});
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = nodeStatus;
|
||||
|
||||
next();
|
||||
|
@ -202,6 +202,7 @@ function createLayergroup (mapBackend, userLimitsBackend, pgConnection, affected
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = layergroup;
|
||||
res.locals.mapConfigProvider = mapConfigProvider;
|
||||
|
||||
|
@ -77,6 +77,7 @@ function getFeatureAttributes (attributesBackend) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = tile;
|
||||
|
||||
next();
|
||||
|
@ -151,6 +151,7 @@ function getDataview (dataviewBackend) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = dataview;
|
||||
|
||||
next();
|
||||
@ -174,6 +175,7 @@ function dataviewSearch (dataviewBackend) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = searchResult;
|
||||
|
||||
next();
|
||||
|
@ -109,6 +109,7 @@ function getPreviewImageByCenter (previewBackend) {
|
||||
|
||||
res.set('Content-Type', headers['Content-Type'] || `image/${format}`);
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = image;
|
||||
|
||||
next();
|
||||
@ -144,6 +145,7 @@ function getPreviewImageByBoundingBox (previewBackend) {
|
||||
|
||||
res.set('Content-Type', headers['Content-Type'] || `image/${format}`);
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = image;
|
||||
|
||||
next();
|
||||
|
@ -268,6 +268,7 @@ function getImage({ previewBackend, label }) {
|
||||
res.set(headers);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = image;
|
||||
|
||||
next();
|
||||
@ -287,6 +288,7 @@ function getImage({ previewBackend, label }) {
|
||||
res.set(headers);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = image;
|
||||
|
||||
next();
|
||||
|
6
lib/cartodb/api/middlewares/initialize-status-code.js
Normal file
6
lib/cartodb/api/middlewares/initialize-status-code.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = function initializeStatusCode () {
|
||||
return function initializeStatusCodeMiddleware (req, res, next) {
|
||||
res.statusCode = 404;
|
||||
next();
|
||||
};
|
||||
};
|
@ -2,7 +2,7 @@ module.exports = function sendResponse () {
|
||||
return function sendResponseMiddleware (req, res) {
|
||||
req.profiler.done('res');
|
||||
|
||||
res.status(res.statusCode || 200);
|
||||
res.status(res.statusCode);
|
||||
|
||||
if (Buffer.isBuffer(res.body)) {
|
||||
return res.send(res.body);
|
||||
|
@ -115,6 +115,7 @@ function createTemplate ({ templateMaps }) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = { template_id: templateId };
|
||||
|
||||
next();
|
||||
@ -133,6 +134,7 @@ function updateTemplate ({ templateMaps }) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = { template_id: templateId };
|
||||
|
||||
next();
|
||||
@ -161,6 +163,7 @@ function retrieveTemplate ({ templateMaps }) {
|
||||
// so we remove it before returning to the user
|
||||
delete template.auth_id;
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = { template };
|
||||
|
||||
next();
|
||||
@ -199,6 +202,7 @@ function listTemplates ({ templateMaps }) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = { template_ids: templateIds };
|
||||
|
||||
next();
|
||||
|
@ -204,6 +204,7 @@ function instantiateLayergroup (mapBackend, userLimitsBackend, pgConnection, aff
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = layergroup;
|
||||
|
||||
const { mapConfigProvider } = res.locals;
|
||||
|
@ -75,6 +75,7 @@ function getTile ({ tileBackend, label }) {
|
||||
res.set(headers);
|
||||
}
|
||||
|
||||
res.statusCode = 200;
|
||||
res.body = tile;
|
||||
|
||||
next();
|
||||
|
Loading…
Reference in New Issue
Block a user