Skip to content

Commit

Permalink
Merge pull request #34911 from dimagi/riese/wait_for_serverup
Browse files Browse the repository at this point in the history
Wait for serverup
  • Loading branch information
MartinRiese authored Aug 2, 2024
2 parents b7a1b1c + a202db0 commit 06556db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
26 changes: 12 additions & 14 deletions corehq/apps/cloudcare/static/cloudcare/js/formplayer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ hqDefine("cloudcare/js/formplayer/app", [
TemplateCache
) {
Marionette.setRenderer(TemplateCache.render);
var FormplayerFrontend = new Marionette.Application();

FormplayerFrontend.on("before:start", function (app, options) {
const xsrfRequest = new $.Deferred();
this.xsrfRequest = xsrfRequest.promise();
// Make a get call if the csrf token isn't available when the page loads.
if ($.cookie('XSRF-TOKEN') === undefined) {
$.get(
{url: options.formplayer_url + '/serverup', global: false, xhrFields: { withCredentials: true }}
).always(() => { xsrfRequest.resolve(); });
} else {
// resolve immediately
xsrfRequest.resolve();
}

const WebApp = Marionette.Application.extend({
getXSRF: function (options) {
return $.get({
url: options.formplayer_url + '/serverup',
global: false, xhrFields: {withCredentials: true},
});
},
});

const FormplayerFrontend = new WebApp();

FormplayerFrontend.on("before:start", function () {
if (!FormplayerFrontend.regions) {
FormplayerFrontend.regions = CloudcareUtils.getRegionContainer();
}
Expand Down
4 changes: 3 additions & 1 deletion corehq/apps/cloudcare/static/cloudcare/js/formplayer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ hqDefine("cloudcare/js/formplayer/main", [
singleAppMode: false,
environment: initialPageData.get('environment'),
};
FormplayerFrontEnd.start(options);
FormplayerFrontEnd.getXSRF(options).then(() =>
FormplayerFrontEnd.start(options)
);

var $menuToggle = $('#commcare-menu-toggle'),
$navbar = $('#hq-navigation'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ hqDefine('cloudcare/js/preview_app/preview_app', [
$(this).attr('target', '_parent');
});

FormplayerFrontend.start(options);
FormplayerFrontend.getXSRF(options).then(() =>
FormplayerFrontend.start(options)
);

if (localStorage.getItem("preview-tablet")) {
FormplayerFrontend.trigger('view:tablet');
Expand Down

0 comments on commit 06556db

Please sign in to comment.