Windshaft-cartodb/lib/api/middlewares/send-response.js

25 lines
599 B
JavaScript
Raw Normal View History

'use strict';
const setCommonHeaders = require('../../utils/common-headers');
2018-03-20 02:48:14 +08:00
module.exports = function sendResponse () {
return function sendResponseMiddleware (req, res, next) {
setCommonHeaders(req, res, () => {
res.status(res.statusCode);
2018-03-20 02:48:14 +08:00
if (Buffer.isBuffer(res.body)) {
res.send(res.body);
return next();
}
2018-03-20 02:48:14 +08:00
if (req.query.callback) {
res.jsonp(res.body);
return next();
}
2018-03-20 02:48:14 +08:00
res.json(res.body);
return next();
});
2018-03-20 02:48:14 +08:00
};
};