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:
Daniel García Aubert 2018-05-09 15:00:18 +02:00
parent 9feea66550
commit c51e254287
13 changed files with 25 additions and 1 deletions

View File

@ -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({

View File

@ -99,6 +99,7 @@ function prepareResponse () {
return -1;
});
res.statusCode = 200;
res.body = { catalog: analysisCatalog };
next();

View File

@ -48,6 +48,7 @@ function analysisNodeStatus (analysisStatusBackend) {
'Last-Modified': new Date().toUTCString()
});
res.statusCode = 200;
res.body = nodeStatus;
next();

View File

@ -202,6 +202,7 @@ function createLayergroup (mapBackend, userLimitsBackend, pgConnection, affected
return next(err);
}
res.statusCode = 200;
res.body = layergroup;
res.locals.mapConfigProvider = mapConfigProvider;

View File

@ -77,6 +77,7 @@ function getFeatureAttributes (attributesBackend) {
return next(err);
}
res.statusCode = 200;
res.body = tile;
next();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -0,0 +1,6 @@
module.exports = function initializeStatusCode () {
return function initializeStatusCodeMiddleware (req, res, next) {
res.statusCode = 404;
next();
};
};

View File

@ -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);

View File

@ -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();

View File

@ -204,6 +204,7 @@ function instantiateLayergroup (mapBackend, userLimitsBackend, pgConnection, aff
return next(err);
}
res.statusCode = 200;
res.body = layergroup;
const { mapConfigProvider } = res.locals;

View File

@ -75,6 +75,7 @@ function getTile ({ tileBackend, label }) {
res.set(headers);
}
res.statusCode = 200;
res.body = tile;
next();