.

A Complete Guide to Deploy GAS as Web App: Guide 002

Introduction

If this is your first time to deploy your Google Apps Script project as a Web App, you can follow this guide to get started.

Minimal Preparation

Youā€™ll need to have a function called doGet in your project to get started.

File ā€œcode.gsā€

/**

* HtmlService.XFrameOptionsMode.ALLOWALL will allow you to embed your web app as an iframe without

* showing the Google Alert message "This application was created by a Google Apps Script user"

*/

function doGet() {

 return HtmlService

   .createHtmlOutputFromFile('index.html')

   .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)

   .setTitle('Hello World')

}

File ā€œindex.htmlā€

<!DOCTYPE html>

<html>

 <head>

   <base target="_top">

 </head>

 <body>

   <h1>Hello World!</h1>

 </body>

</html>

Step 1

Start the deployment by selecting either ā€œNew deploymentā€ or ā€œManage deploymentsā€. For the 1st deployment, you can only start with ā€œNew deploymentā€, and for the later deployments we usually use ā€œManage deploymentsā€ to keep the Web App URL unchanged. Itā€™s important to remember that every ā€œNew deploymentā€ will create a new Web App URL.

Step 2

Select ā€œWeb appā€ as the type for the deployment.

Step 3

Fill the configuration form, and click the deploy button.

  • Version: New version
  • Description: Any information that helps to describe the new version
  • Execute as
  • Me (your email address)
  • User accessing the web app
  • Who has access
  • Only myself
  • Anyone with domain (for workspace/enterprise account only)
  • Anyone with Google account
  • Anyone

Step 4 (Optional)

If your app needs your authorization to access your data, or you updated your project with new scopes or Google API services youā€™ll need to complete the authorization process by following this post.

Step 5

Finally, you should be able to get the URL which ends with ā€œ/execā€ to your Web App. This is the production URL of your project which uses the latest code in your latest deployment. Copy it and have a try with the link in your browser to visit your app. You donā€™t have to save it since you always can find it in the ā€œManage deploymentsā€.

For the devs, you can find the test URL which ends with ā€œ/devā€ to the Web App. The test URL will always use the latest code in your project. Please note this link is only accessible for yourself, other people canā€™t access it.

If you followed all the steps above, you should have your first web app deployed successfully. You can embed the web app as an iframe in other websites if you want. To get rid of the Google Alert ā€œThis application was created by a Google Apps Script userā€ in the embed web site, you can set HtmlService.XFrameOptionsMode.ALLOWALL in the function doGet.

GoogleAppsScript Playlist

LiveCoding Playlist

OneScript Playlist


Chalkline Playlist

RoadTripPhotography Playlist


OnTheRoad Playlist

Links

Github(@ashtonfei) 

YouTube(@ashtonfei) 

Twitter (@ashton_fei) 

Instagram (@ashton.fei) 

Upwork (work with me) 

OneScript (my website)

YouTube(@ashtontheroad) 

Comments