65.9K
CodeProject is changing. Read more.
Home

Custom Domains on Google Apps Script

starIconstarIconstarIconstarIconstarIcon

5.00/5 (3 votes)

Jun 4, 2017

CPOL
viewsIcon

18391

Making your apps script URLs a lot more attractive

It may have occurred to you that when deploying a Google Apps Script web app, the URL spewn forth looks rather long and unattractive:

https://script.google.com/macros/s/*mashes keyboard*/exec

And that it would be a lot nicer to have something more succinct like:

https://mysite.com/thing

Well, this has indeed troubled and racked the minds of many a stackoverflow poster trying to circumvent Google’s top-notch cross-domain prevention skills… until now…

It turns out that the solution to hosting Google Apps Script web apps on custom domains has been under our noses for all this time. The secret sauce lies in the setXFrameOptionsMode method in the HtmlService class. It takes an enum of one of two values: DEFAULTor ALLOWALL. What we want to do is to set this to ALLOWALL.

return HtmlService
     .createTemplateFromFile('login')
     .evaluate()
     .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

This now means that we are at liberty to embed our app into any page using an iframe. It even supports SSL.

<iframe src="https://script.google.com/macros/s/*mashes keyboard*/exec"></iframe>

And the end result is something quite stunning.

Notice how the URL doesn’t take up the entire address bar.

That’s all for today folks. Creds to Stewart for discovering this madness.

Original blog post (by yours truly): https://medium.com/nuclear-chicken/custom-domains-on-google-apps-script-46734fb8b4b6