Windshaft-cartodb/lib/cartodb/controllers/base.js
2017-09-29 11:07:11 +02:00

41 lines
945 B
JavaScript

var debug = require('debug')('windshaft:cartodb');
function BaseController() {
}
module.exports = BaseController;
// jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) {
if (res.locals.dbhost) {
res.set('X-Served-By-DB-Host', res.locals.dbhost);
}
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
if (headers) {
res.set(headers);
}
res.status(status);
if (!Buffer.isBuffer(body) && typeof body === 'object') {
if (req.query && req.query.callback) {
res.jsonp(body);
} else {
res.json(body);
}
} else {
res.send(body);
}
try {
// May throw due to dns, see
// See http://github.com/CartoDB/Windshaft/issues/166
req.profiler.sendStats();
} catch (err) {
debug("error sending profiling stats: " + err);
}
};
// jshint maxcomplexity:6