From 815c4b3f572de899773f8646ad8ca71439a4c975 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Thu, 26 Nov 2015 11:59:25 -0800 Subject: [PATCH 1/2] Support redirect responses from API calls Several scratchr2 views do a thing and then redirect (project, studio creation, the student password reset middleware). This allows the client to redirect to that response. Fixes GH-238. Requires LLK/scratchr2@bf451a95ea5f1af224c50953074cdb24d1e1492e --- src/mixins/api.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mixins/api.jsx b/src/mixins/api.jsx index 56f3194fe..5ce996458 100644 --- a/src/mixins/api.jsx +++ b/src/mixins/api.jsx @@ -34,6 +34,7 @@ var Api = { } xhr(opts, function (err, res, body) { if (err) log.error(err); + if (body && body[0] && 'redirect' in body[0]) window.location = body[0].redirect; callback(err, body); }); }.bind(this); From 68bcbf75114e36d59c2e794ede20b74d51f3a5c8 Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Thu, 10 Dec 2015 17:11:25 -0500 Subject: [PATCH 2/2] Explain strange redirect behavior --- src/mixins/api.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mixins/api.jsx b/src/mixins/api.jsx index 5ce996458..c4cd069a3 100644 --- a/src/mixins/api.jsx +++ b/src/mixins/api.jsx @@ -34,6 +34,8 @@ var Api = { } xhr(opts, function (err, res, body) { if (err) log.error(err); + // Legacy API responses come as lists, and indicate to redirect the client like + // [{success: true, redirect: "/location/to/redirect"}] if (body && body[0] && 'redirect' in body[0]) window.location = body[0].redirect; callback(err, body); });