2015-09-17 17:06:46 +08:00
|
|
|
var debug = require('debug')('windshaft:cartodb');
|
2015-09-16 22:18:26 +08:00
|
|
|
|
2017-09-25 19:40:22 +08:00
|
|
|
function BaseController() {
|
2015-09-16 22:18:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-09-17 03:54:56 +08:00
|
|
|
}
|
|
|
|
|
2017-03-31 02:31:53 +08:00
|
|
|
res.set('X-Tiler-Profiler', req.profiler.toJSONString());
|
2015-09-17 03:54:56 +08:00
|
|
|
|
2015-09-17 08:03:09 +08:00
|
|
|
if (headers) {
|
|
|
|
res.set(headers);
|
2015-09-17 03:54:56 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 08:04:30 +08:00
|
|
|
res.status(status);
|
2015-09-17 03:54:56 +08:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-03-31 02:31:53 +08:00
|
|
|
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 03:54:56 +08:00
|
|
|
}
|
|
|
|
};
|
2015-09-17 08:03:09 +08:00
|
|
|
// jshint maxcomplexity:6
|