This tool is a URL Shortening service powered by Google Apps Script and hosted using Github Pages.
~Taking advantage of an undocumented resource from the doGet
function that I accidentally stumbled upon - e.pathInfo
while working on a completely different project.~
You can try TakeMeThere on https://tmt.pw/ and access the original resources here -
With the current architecture, while "redirecting" from the short URL to the destination (long) URL, the Apps Script web app link is exposed and visible. Here's what I mean -
For now, the 404s are more of an "alert" box, that's then redirected to the main domain.
Yeah, I know this may sound super annoying but that, something that most folks would call the holy grail for using URL shortening services, is still under my bucket list.
These may be (and I'm not trying to be too hard on myself here) deal-breakers for a few and so I'd rather you know about them before you're exposed to the excruciating documentation 😅
setup
phasesheetID
with the Spreadsheet ID that you could find from the URL of your newly created sheet in step 1
https://docs.google.com/spreadsheets/d/
RandomStringOfCharactersHere/edit
sheetID
, fill in your domain name under customDomain
& a name that you'd want to display under serviceName
https
will be enforced in the coming stages, when we start working with Github PagesSetup.gs
script file within apps script and run the setup
function. Here, it would ask you to authorise the script - do it! The function would do 3 things:
Save the link somewhere as we'll need it in the later stages of this setup.
index.html
& 404.html
files from this repository to your ownindex.html
file from your respository and replace the links (from lines 41 & 70) that contain a script.google.com
URL to the one (your own) that you'd have saved from the previous stage
<title>
tag from line 5404.html
file (courtesy Rafael Pedicini)Please follow through what's available with configuring an apex domain. My approach was to create A records that point to the following IP addresses for GitHub Pages -
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
Wait for the DNS propogation to take place - can vary somewhere between 5 minutes to 78 hours (or more).
The setup uses the following third party dependecies (notwithstanding the obvious ones, those of which have been defined under prerequisites)
Once you have everything setup, you can then navigate to your domain (in this case, https://tmt.pw/) and -
Enter
or click CREATEopen this image in a new tab for better clarity / resolution
You can also clear the fields by clicking on the (Red) 'CLEAR' button. It has currently not been automated (intentionally) as the final display (that comes up in Green) consumes the slug from this form.
The script within the Code.gs
file checks for a few kinds of validations within different parts of the process.
https://example.com/
slug)I'm new here, this is my first open-source project & I'm not actually a coder/techie or a programmer - just super enthusiastic about Google Apps Script with a huge self-centered need to brag.
If you've read through this documentation so far - I know, this is such a cliché thing to say - and want to contribute, please feel free to create pull requests with your recommendations or write to me on code@script.gs
.
This project would've not been possible (by me), had I not found my way through to the following resources -
e.pathInfo
doPost
to create new short URLsNo. This setup simply uses window.open
to have a new URL loaded on the same browser window (using _top
), based on the slug.
Turns out
e.pathInfo
was a bad idea! Switched my code back toe.queryString
.
[Resolved] I got to know about this odd behavior only by the end of fully dpeloying this solution and the scenario being while a user would not be prompted to login when they create short URLs (via custom domain), they would be prompted to login when they visit a shortened URL (if they've not already logged in to their Google accounts on that browser).
A simple view of all things that have been changed can be tracked here
MIT License
Copyright (c) 2019 Sourabh Choraria
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.