2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-20 02:48:14 +08:00
|
|
|
module.exports = function sendResponse () {
|
2020-02-25 21:14:20 +08:00
|
|
|
return function sendResponseMiddleware (req, res, next) {
|
2018-05-09 21:00:18 +08:00
|
|
|
res.status(res.statusCode);
|
2018-03-20 02:48:14 +08:00
|
|
|
|
|
|
|
if (Buffer.isBuffer(res.body)) {
|
2020-02-25 21:14:20 +08:00
|
|
|
res.send(res.body);
|
|
|
|
return next();
|
2018-03-20 02:48:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.query.callback) {
|
2020-02-25 21:14:20 +08:00
|
|
|
res.jsonp(res.body);
|
|
|
|
return next();
|
2018-03-20 02:48:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
res.json(res.body);
|
2020-02-25 21:14:20 +08:00
|
|
|
return next();
|
2018-03-20 02:48:14 +08:00
|
|
|
};
|
|
|
|
};
|