Windshaft-cartodb/lib/cartodb/controllers/base.js

41 lines
945 B
JavaScript
Raw Normal View History

2015-09-17 17:06:46 +08:00
var debug = require('debug')('windshaft:cartodb');
function BaseController() {
}
module.exports = BaseController;
2015-09-17 08:03:09 +08:00
// jshint maxcomplexity:9
BaseController.prototype.send = function(req, res, body, status, headers) {
2017-09-29 17:07:11 +08:00
if (res.locals.dbhost) {
res.set('X-Served-By-DB-Host', res.locals.dbhost);
}
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
2015-09-17 08:03:09 +08:00
if (headers) {
res.set(headers);
}
2015-09-17 08:04:30 +08:00
res.status(status);
2015-09-17 08:04:30 +08:00
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);
}
};
2015-09-17 08:03:09 +08:00
// jshint maxcomplexity:6