Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Last active May 6, 2024 02:34
Show Gist options
  • Save tanaikech/ebf92d8f427d02d53989d6c3464a9c43 to your computer and use it in GitHub Desktop.
Save tanaikech/ebf92d8f427d02d53989d6c3464a9c43 to your computer and use it in GitHub Desktop.
Redeploying Web Apps without Changing URL of Web Apps for new IDE

Redeploying Web Apps without Changing URL of Web Apps for new IDE

At March 15, 2021, one endpoint is created for one deployment. Ref By this, when you redeploy "Web Apps", the endpoint is changed. Because the deployment ID is changed. It seems that this it the new specification. In this report, I would like to introduce the method for redeploying Web Apps without changing the URL of Web Apps for new IDE.

Deploy Web Apps

  1. Open "New deployment" dialog with "Deploy" -> "New deployment".

  2. Select "Web app" for "Select type".

  3. Input "Description" and as a sample, set "Web apps" as follows.

    • Execute as: Me
    • Who has access: Anyone

  4. Click "Deploy" button. And, copy the URL of "Web app" and click "Done" button. By this, you can see the following endpoint.

    • https://script.google.com/macros/s/###/exec

IMPORTANT POINT

  • When the script of Web Apps is changed and redeploy Web Apps, after March 15, 2021, the endpoint is changed. This is new specification. Because the deployment ID of ### in https://script.google.com/macros/s/###/exec is changed.

By this, there is an issue that the endpoint is changed. When you want to use the same endpoint by reflected the latest script to Web Apps, please do the following flow.

  1. Create new Google Apps Script project and copy and paste the following script.

    function doGet() {
      return ContentService.createTextOutput("sample1");
    }
  2. Deploy Web Apps as the following settings.

    • Execute as: Me
    • Who has access: Anyone
  3. Test the Web Apps using the following curl command.

    $ curl -L "https://script.google.com/macros/s/###/exec"
    • Please confirm that sample1 is returned.
  4. Modify the script of Web Apps as follows.

    function doGet() {
      return ContentService.createTextOutput("sample2"); // Modified
    }
  5. Update the deployment as follows.

    1. Open "New deployment" dialog with "Deploy" -> "Manage deployments".
    2. For the 1st deployment, click the pencil icon for editing the deployment.
    3. Set "version" as "New version".
    4. When you want to change the description, please modify it.
    5. Click "Deploy" button.
  6. Testing.

    • Please use above sample curl command. By this, you can confirm that sample2 is returned without changing the endpoint.

References

@doughazell
Copy link

Thank you very much for your input. I am trying to insert an image into a google sheet from https://github.com/doughazell/ionic-camera-swipe and this is only available in Google Apps Script (when everything else is done with Google Sheets API). I needed to do as you state after altering the static dev code in the 'doGet()' (since 'doPost()' isn't working at the moment).

@tanaikech
Copy link
Author

@doughazell
Thank you for your comment. If this post was useful, I'm glad.

@cclambie
Copy link

cclambie commented Dec 7, 2022

is there anyway to "do" stuff without needing to redeploy every time?
small changes to script?

I am thinking a 2nd script file?
Or similar?
I tried a function that did the work, ie. Function DoStuff(var) {}, but that didn't work :(

@tanaikech
Copy link
Author

@cclambie About your question, now, I posted it on my blog. https://tanaikech.github.io/2022/12/07/workaround-reflecting-latest-script-to-deployed-web-apps-created-by-google-apps-script-without-redeploying/ Could you please confirm it? But, if that was not your expected direction, I apologize.

@cclambie
Copy link

Hey @tanaikech ,
I have run into a couple of issues.

  1. When I add the library file appsscript.json to Project 1, it appends .html to the file in Google Script editor
  2. If I try to "run" a test function in Project 2, I get "obj not defined"
    Maybe related?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment