Heroku w/ Subdomains
Last updated
Was this helpful?
Last updated
Was this helpful?
The easiest way to deploy the frontend that uses the multi-tenant with subdomains strategy is probably on Heroku.
Tenant Mode set to Multi w/ Subdomain.
Custom Domain
Heroku Account with billing enabled
frontend/src/config/production.tsx (For React and Vue)
frontend/src/environments/environment.production.ts (For Angular)
Replace the backendUrl
variable for the corresponding URL.
Don't forget the/api
suffix.
Replace the frontend.host
for your custom domain.
Heroku does not have a way of hosting static files, so we must set an ExpressJS server to serve our static files.
frontend/Procfile
frontend/server.js
Replace Line 5 with the one for the corresponding front-end framework you are using.
The server.js needs express
and express-history-api-fallback
.
Heroku starts the application by running npm start
, so you must change the start script to run the ExpressJS server file.
frontend/package.json
Now if you want to start the frontend, you will have to run npm run start:frontend
.
Go to the frontend repository and run:
Install the Heroku CLI
Sign in to Heroku
Create a new application
Make sure you are at the frontend repository an run:
You will then receive the app URL. Save it for accessing later.
Push the code to Heroku and deploy it.
Great! The app is now online.
To activate the subdomain capabilities, you'll have to add a wildcard Custom Domain.
Add the CNAME record on the custom domain provider DNS.
To discover the CNAME, run:
You must also add a URL Redirect Record to point your root domain to www.
I use Namecheap as the domain provider, so my DNS configuration starts looking like this:
It might take a few minutes, but you will be ready to use your URL without SSL.
It will be accessible via http.
Because of the wildcard, Heroku does not automatically assign a certificate for us. We must create it using CertBot.
After installed, run the command below, changing the YOUR_CUSTOM_DOMAIN for your domain.
Follow the instructions. You will have to create a DNS TXT record.
Ok, now you have your certificate saved at /etc/letsencrypt/live/your_custom_domain.
This is required to upload SSL certificates.
Done! Now your application can be accessed via subdomains and with https.
More information at .
For more information, read .
Install CertBot: .
Before hitting next, make sure the TXT variables are configured correctly using a tool like . Make sure you have TXT Lookup selected.
More information at .