Heroku is one of the most popular PAAS provider, I am using this to show serve a very small yet impactful service: Redirect various product url from a single source.
Example first, I maintain a date conversion library (which we migrated to Jest). In order to share its url to all, I can give the Github url to them. Or, I can create a subdomain in my primary domain and redirect visitors to that particular Github page.
The second approach will give a bit personalized touch than the former one. So, I took this aproach and I’ve implemented the redirection via Python3 and Flask; and made use of heroku apps to scale it. Once it was published via Heroku, I created custom DNS direction in Cloudflare and the resultant heroku app is served via http://redirect.mythicangel.com/bangladatejs url. Being in PAAS system, it is cloud native and scalable 🙂
So, what are the steps? Follow in this order:
- Create a new python app by following official instruction from Heroku.
Just remember 2 thing:
- If you’re using Ubuntu, then don’t follow their guideline to install cli from source. Instead download it via snap command.
- Must use virtualenv to avoid the installation mess of python2 and python3.
- Collect the DNS value in one of these 2 steps:
- Go to the app’s Settings and add a new custom domain which you want to add. You may have to verify your account beforehand via credit card. Once you add the custom domain, heroku will give you corresponding value for DNS target. This DNS value you’ll need to use as CNAME value in your DNS registrar (We don’t this url for cloudflare by the way)
- Just copy the app’s url without https:// prefix (e.g. example-name.herokuapp.com)
- Go to cloudflare and open DNS tab of the domain (where the subdomain will be created)
- Add a new record of type “CNAME” (bydefault A will be selected). In the subdomain field, give your desired subdomain (e.g. redirect as in my case) and in the CNAME field, give the DNS value from step-ii. I will suggest to use ii.ii (just try to create the app’s name in a unique way so that no one can guess it)
- Done 🙂