User res.body as placeholder of the response's body
This commit is contained in:
parent
7bdbd4cb03
commit
e52cd28f1e
@ -224,9 +224,11 @@ function getTile ({ tileBackend, label }) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.body = tile;
|
if (headers) {
|
||||||
res.locals.headers = headers;
|
res.set(headers);
|
||||||
res.locals.stats = stats;
|
}
|
||||||
|
|
||||||
|
res.body = tile;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -350,28 +352,36 @@ function getImage({ previewBackend, label }) {
|
|||||||
if (zoom !== undefined && center) {
|
if (zoom !== undefined && center) {
|
||||||
return previewBackend.getImage(namedMapProvider, format, width, height, zoom, center,
|
return previewBackend.getImage(namedMapProvider, format, width, height, zoom, center,
|
||||||
(err, image, headers, stats) => {
|
(err, image, headers, stats) => {
|
||||||
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.body = image;
|
if (headers) {
|
||||||
res.locals.headers = headers;
|
res.set(headers);
|
||||||
res.locals.stats = stats;
|
}
|
||||||
|
|
||||||
|
res.body = image;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
previewBackend.getImage(namedMapProvider, format, width, height, bounds, (err, image, headers, stats) => {
|
previewBackend.getImage(namedMapProvider, format, width, height, bounds, (err, image, headers, stats) => {
|
||||||
|
req.profiler.add(stats);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
err.label = label;
|
err.label = label;
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.body = image;
|
if (headers) {
|
||||||
res.locals.headers = headers;
|
res.set(headers);
|
||||||
res.locals.stats = stats;
|
}
|
||||||
|
|
||||||
|
res.body = image;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -498,9 +508,8 @@ function setCacheControlHeader () {
|
|||||||
|
|
||||||
function setContentTypeHeader () {
|
function setContentTypeHeader () {
|
||||||
return function setContentTypeHeaderMiddleware(req, res, next) {
|
return function setContentTypeHeaderMiddleware(req, res, next) {
|
||||||
const { headers = {} } = res.locals;
|
|
||||||
|
|
||||||
res.set('Content-Type', headers['content-type'] || headers['Content-Type'] || 'image/png');
|
res.set('Content-Type', res.get('content-type') || res.get('Content-Type') || 'image/png');
|
||||||
|
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
@ -508,12 +517,11 @@ function setContentTypeHeader () {
|
|||||||
|
|
||||||
function sendResponse () {
|
function sendResponse () {
|
||||||
return function sendResponseMiddleware (req, res) {
|
return function sendResponseMiddleware (req, res) {
|
||||||
const { body, stats = {}, format } = res.locals;
|
const { format } = res.locals;
|
||||||
|
|
||||||
req.profiler.done('render-' + format);
|
req.profiler.done('render-' + format);
|
||||||
req.profiler.add(stats);
|
|
||||||
|
|
||||||
res.status(200);
|
res.status(200);
|
||||||
res.send(body);
|
res.send(res.body);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user