mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
5ffdfe9875
no-issue
37 lines
789 B
JavaScript
37 lines
789 B
JavaScript
function getData(...props) {
|
|
return function (req, res, next) {
|
|
if (!req.body) {
|
|
res.writeHead(400);
|
|
return res.end();
|
|
}
|
|
|
|
const data = props.concat('origin').reduce((data, prop) => {
|
|
if (!data || !req.body[prop]) {
|
|
return null;
|
|
}
|
|
return Object.assign(data, {
|
|
[prop]: req.body[prop]
|
|
});
|
|
}, {});
|
|
|
|
if (!data) {
|
|
res.writeHead(400);
|
|
return res.end(`Expected {${props.join(', ')}}`);
|
|
}
|
|
req.data = data || {};
|
|
next();
|
|
};
|
|
}
|
|
|
|
function handleError(status, res) {
|
|
return function () {
|
|
res.writeHead(status);
|
|
res.end();
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
getData,
|
|
handleError
|
|
};
|