Ensure application/json on library flows reqs

This commit is contained in:
Nick O'Leary
2014-11-05 22:41:05 +00:00
parent e7eb02fcb7
commit a520240b25
5 changed files with 47 additions and 31 deletions

View File

@@ -31,10 +31,10 @@ var errorHandler = function(err,req,res,next) {
function init(adminApp) {
library.init(adminApp);
adminApp.use(express.json());
library.init(adminApp);
// Editor
if (!settings.disableEditor) {
adminApp.get("/",ui.ensureSlash);

View File

@@ -47,19 +47,19 @@ function createLibrary(type) {
var path = req.params[0];
var fullBody = '';
req.on('data', function(chunk) {
fullBody += chunk.toString();
fullBody += chunk.toString();
});
req.on('end', function() {
storage.saveLibraryEntry(type,path,req.query,fullBody).then(function() {
res.send(204);
}).otherwise(function(err) {
util.log("[red] Error saving library entry '"+path+"' : "+err);
if (err.message.indexOf('forbidden') === 0) {
res.send(403);
return;
}
res.send(500);
});
storage.saveLibraryEntry(type,path,req.query,fullBody).then(function() {
res.send(204);
}).otherwise(function(err) {
util.log("[red] Error saving library entry '"+path+"' : "+err);
if (err.message.indexOf('forbidden') === 0) {
res.send(403);
return;
}
res.send(500);
});
});
});
}
@@ -91,22 +91,16 @@ module.exports = {
});
},
post: function(req,res) {
//TODO: do content-type properly
var fullBody = '';
req.on('data', function(chunk) {
fullBody += chunk.toString();
});
req.on('end', function() {
storage.saveFlow(req.params[0],fullBody).then(function() {
res.send(204);
}).otherwise(function(err) {
util.log("[red] Error loading flow '"+req.params[0]+"' : "+err);
if (err.message.indexOf('forbidden') === 0) {
res.send(403);
return;
}
res.send(500);
});
var flow = JSON.stringify(req.body);
storage.saveFlow(req.params[0],flow).then(function() {
res.send(204);
}).otherwise(function(err) {
util.log("[red] Error loading flow '"+req.params[0]+"' : "+err);
if (err.message.indexOf('forbidden') === 0) {
res.send(403);
return;
}
res.send(500);
});
}
}