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