1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Avoid http redirects as Safari doesn't reuse Auth header

Fixes #1903
This commit is contained in:
Nick O'Leary 2018-10-19 14:03:22 +01:00
parent 34ead436b0
commit f22960ad59
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -20,6 +20,58 @@ var apiUtils = require("../util");
var runtimeAPI;
var needsPermission = require("../auth").needsPermission;
function listProjects(req,res) {
var opts = {
user: req.user
}
runtimeAPI.projects.listProjects(opts).then(function(result) {
res.json(result);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
});
}
function getProject(req,res) {
var opts = {
user: req.user,
id: req.params.id
}
runtimeAPI.projects.getProject(opts).then(function(data) {
if (data) {
res.json(data);
} else {
res.status(404).end();
}
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
}
function getProjectStatus(req,res) {
var opts = {
user: req.user,
id: req.params.id,
remote: req.query.remote
}
runtimeAPI.projects.getStatus(opts).then(function(data){
if (data) {
res.json(data);
} else {
res.status(404).end();
}
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
}
function getProjectRemotes(req,res) {
var opts = {
user: req.user,
id: req.params.id
}
runtimeAPI.projects.getRemotes(opts).then(function(data) {
res.json(data);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
}
module.exports = {
init: function(_runtimeAPI) {
runtimeAPI = _runtimeAPI;
@ -40,16 +92,7 @@ module.exports = {
// Projects
// List all projects
app.get("/", needsPermission("projects.read"), function(req,res) {
var opts = {
user: req.user
}
runtimeAPI.projects.listProjects(opts).then(function(result) {
res.json(result);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
});
});
app.get("/", needsPermission("projects.read"),listProjects);
// Create project
app.post("/", needsPermission("projects.write"), function(req,res) {
@ -74,13 +117,13 @@ module.exports = {
if (req.body.active) {
runtimeAPI.projects.setActiveProject(opts).then(function() {
res.redirect(303,req.baseUrl + '/');
listProjects(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
} else if (req.body.initialise) {
runtimeAPI.projects.initialiseProject(opts).then(function() {
res.redirect(303,req.baseUrl + '/'+ req.params.id);
getProject(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -91,7 +134,7 @@ module.exports = {
req.body.hasOwnProperty('files') ||
req.body.hasOwnProperty('git')) {
runtimeAPI.projects.updateProject(opts).then(function() {
res.redirect(303,req.baseUrl + '/'+ req.params.id);
getProject(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -101,21 +144,7 @@ module.exports = {
});
// Get project metadata
app.get("/:id", needsPermission("projects.read"), function(req,res) {
var opts = {
user: req.user,
id: req.params.id
}
runtimeAPI.projects.getProject(opts).then(function(data) {
if (data) {
res.json(data);
} else {
res.status(404).end();
}
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
});
app.get("/:id", needsPermission("projects.read"), getProject);
// Delete project
app.delete("/:id", needsPermission("projects.write"), function(req,res) {
@ -132,22 +161,7 @@ module.exports = {
// Get project status - files, commit counts, branch info
app.get("/:id/status", needsPermission("projects.read"), function(req,res) {
var opts = {
user: req.user,
id: req.params.id,
remote: req.query.remote
}
runtimeAPI.projects.getStatus(opts).then(function(data){
if (data) {
res.json(data);
} else {
res.status(404).end();
}
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
});
app.get("/:id/status", needsPermission("projects.read"), getProjectStatus);
// Project file listing
@ -203,7 +217,7 @@ module.exports = {
path: req.params[0]
}
runtimeAPI.projects.stageFile(opts).then(function() {
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
getProjectStatus(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -217,7 +231,7 @@ module.exports = {
path: req.body.files
}
runtimeAPI.projects.stageFile(opts).then(function() {
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
getProjectStatus(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -231,7 +245,7 @@ module.exports = {
message: req.body.message
}
runtimeAPI.projects.commit(opts).then(function() {
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
getProjectStatus(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -245,7 +259,7 @@ module.exports = {
path: req.params[0]
}
runtimeAPI.projects.unstageFile(opts).then(function() {
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
getProjectStatus(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -258,7 +272,7 @@ module.exports = {
id: req.params.id
}
runtimeAPI.projects.unstageFile(opts).then(function() {
res.redirect(303,req.baseUrl+"/"+opts.id+"/status");
getProjectStatus(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -442,17 +456,7 @@ module.exports = {
});
// Get a list of remotes
app.get("/:id/remotes", needsPermission("projects.read"), function(req, res) {
var opts = {
user: req.user,
id: req.params.id
}
runtimeAPI.projects.getRemotes(opts).then(function(data) {
res.json(data);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
});
app.get("/:id/remotes", needsPermission("projects.read"), getProjectRemotes);
// Add a remote
app.post("/:id/remotes", needsPermission("projects.write"), function(req,res) {
@ -466,7 +470,7 @@ module.exports = {
return;
}
runtimeAPI.projects.addRemote(opts).then(function(data) {
res.redirect(303,req.baseUrl+"/"+opts.id+"/remotes");
getProjectRemotes(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})
@ -480,7 +484,7 @@ module.exports = {
remote: req.params.remoteName
}
runtimeAPI.projects.removeRemote(opts).then(function(data) {
res.redirect(303,req.baseUrl+"/"+opts.id+"/remotes");
getProjectRemotes(req,res);
}).catch(function(err) {
apiUtils.rejectHandler(req,res,err);
})