mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-13 21:06:16 +08:00
fixed overwrite bug when PUTing resources
This commit is contained in:
@@ -50,7 +50,6 @@ module.exports = function (req, res, next, end) {
|
||||
} else {
|
||||
module.exec(req, function (err, data) {
|
||||
res.data = data;
|
||||
|
||||
next();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,6 +27,23 @@ module.exports = require('mdoq')
|
||||
// build full mongodb url
|
||||
this.url = url + (path || this.url);
|
||||
|
||||
if(req.method === 'PUT' && req.resource && req.resource.type != 'Static') {
|
||||
var oldBody = req.body
|
||||
, body = {$set: oldBody.$set || {}};
|
||||
|
||||
Object.keys(oldBody).forEach(function (p) {
|
||||
if(p === '$set') return;
|
||||
if(p && p[0] === '$') {
|
||||
body[p] = oldBody[p];
|
||||
} else {
|
||||
body.$set[p] = oldBody[p];
|
||||
}
|
||||
})
|
||||
|
||||
// rewrite body to $set
|
||||
req.body = body;
|
||||
}
|
||||
|
||||
end(mongo);
|
||||
next();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user