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
Comments
Post a Comment