[P04] Serve custom domain via Heroku

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:

  1. Create a new python app by following official instruction from Heroku.
    Just remember 2 thing:

    1. If you’re using Ubuntu, then don’t follow their guideline to install cli from source. Instead download it via snap command.
    2. Must use virtualenv to avoid the installation mess of python2 and python3.
  2. 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
  3. Once you add the custom domain, heroku will give you corresponding value for DNS target. Copy this url
  4. Go to cloudflare and open DNS tab of the domain (where the subdomain will be created)
  5. 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-iii.
  6. Done 🙂