Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a Google Apps Script WebApp is running in /dev mode

Is there any way to determine whether a web app is running in dev mode or as a properly published version?

I tried getting the URL at both front and back ends.

If I query

window.location.href 

at the front end I don't get the URL displayed in the page address bar, which ends in /dev or /exec. Instead I get a URL that ends in /userCodeAppPanel - I'm guessing because it's been sanitized.

If I call the backend

ScriptApp.getService().getUrl() 

and pass it to the front end it always shows the /exec URL, even if the script is in /dev mode.

I wanted to set DEBUG flags on or off depending on which mode the script was running in.

Any ideas? Thanks.

like image 652
alfiethecoder Avatar asked Jul 27 '17 15:07

alfiethecoder


1 Answers

I had the need to determine if the script is in dev mode as well and couldn't find a solution either. But here's a work around that would work. It requires a manual step every time you publish a production version.

During development:

  • Set a dev flag to true.
  • Code that need to be aware of the dev/production mode needs to check that flag.

Before publishing:

  • Set the dev flag to false.
  • Publish the web app.

After publishing:

  • Revert the dev flag to true.

This would allow segmentation of resources used by dev and production versions.

like image 53
yfaway Avatar answered Oct 14 '22 03:10

yfaway