ScaffoldHub - v2
  • Introduction
  • Modeling
    • Two-way Relationships
  • Setup
    • Backend
    • Frontend
    • File Storage
    • Emails with SendGrid
    • Payments with Stripe
  • Debugging
  • Deployment
    • Database
      • SQL
      • MongoDB
    • Backend
      • Google Cloud - App Engine
      • Google Cloud - Run
      • Under construction...
    • Frontend
      • Firebase Hosting
      • Heroku w/ Subdomains
      • Under construction...
  • Features
    • Projects
    • Preview
    • Tenants
      • Single-Tenant
      • Multi-Tenant
      • Multi-Tenant (w/ subdomains)
    • Payments
    • Security
    • Authentication
      • Sign-in and Sign-up
      • Invitation
      • Password Reset
      • Password Change
      • Email Verification
    • Audit Logs
    • Settings
    • Internationalization (I18n)
    • Entity
      • Form
      • Filter and List
      • Export
      • Import
    • API Documentation
  • Architecture
    • Security
    • File Storage
    • Internationalization (I18n)
    • Payments
    • Typescript Support
    • Rate limiting
    • Technologies Versions
    • Under construction...
  • Recipes
    • Testing the API with Postman
    • Enterprise sign-in with WorkOS
    • Under construction...
  • Support
  • Changelog
    • Documentation
    • Scaffolds
  • Custom Development
  • Legacy Scaffolds
  • Go to ScaffoldHub
Powered by GitBook
On this page
  • Requirements
  • Update the frontend configuration
  • Add the server files to your project
  • Initialize a GitHub repository
  • Create a Heroku project
  • Deploy the app
  • Adding a wildcard domain
  • Configuring the DNS
  • Configuring the SSL certificate
  • Upgrade your Heroku dynos to Hobby
  • Upload the certificate to Heroku

Was this helpful?

  1. Deployment
  2. Frontend

Heroku w/ Subdomains

PreviousFirebase HostingNextUnder construction...

Last updated 3 years ago

Was this helpful?

The easiest way to deploy the frontend that uses the multi-tenant with subdomains strategy is probably on Heroku.

Requirements

  • Tenant Mode set to Multi w/ Subdomain.

  • Custom Domain

  • Heroku Account with billing enabled

Update the frontend configuration

  • 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.

// Place the URL here with the /api suffix.
// Ex.:`https://domain.com/api`;
const backendUrl = `https://your_production_backend_url/api`;

const frontendUrl = {
 host: 'scaffoldhub-demo.xyz',
 protocol: 'https',
};

Add the server files to your project

Heroku does not have a way of hosting static files, so we must set an ExpressJS server to serve our static files.

frontend/Procfile

web: node server $PORT

frontend/server.js

const express = require('express');
const app = express();
const fallback = require('express-history-api-fallback');

const root = `${__dirname}/build`;
app.use(express.static(root));

// history fallback
app.use(fallback('index.html', { root }));

app.listen(process.env.PORT, () =>
  console.log(
    `server is listening on port ${process.env.PORT}`,
  ),
);

Replace Line 5 with the one for the corresponding front-end framework you are using.

# React
const root = `${__dirname}/build`;
# Vue
const root = `${__dirname}/dist`;
# Angular
const root = `${__dirname}/dist/frontend`;

The server.js needs express and express-history-api-fallback.

npm install express 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

{
  ...
  "scripts": {      
      "start": "node server.js",
      "start:frontend": "npm run start:localhost",
  },
  ...
}

Now if you want to start the frontend, you will have to run npm run start:frontend .

Initialize a GitHub repository

Go to the frontend repository and run:

git init
git add --all
git commit -m "Initial Commit"

Create a Heroku project

Install the Heroku CLI

Sign in to Heroku

heroku login

Create a new application

Make sure you are at the frontend repository an run:

heroku create your-app-name

You will then receive the app URL. Save it for accessing later.

Deploy the app

Push the code to Heroku and deploy it.

git push heroku master

Great! The app is now online.

Adding a wildcard domain

To activate the subdomain capabilities, you'll have to add a wildcard Custom Domain.

heroku domains:add "*.your_custom_domain.com"

Configuring the DNS

Add the CNAME record on the custom domain provider DNS.

To discover the CNAME, run:

heroku domains

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.

Configuring the SSL certificate

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.

sudo certbot certonly \
--server https://acme-v02.api.letsencrypt.org/directory \
--manual --preferred-challenges dns \
-d \*.YOUR_CUSTOM_DOMAIN.com -d YOUR_CUSTOM_DOMAIN.com

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.

Upgrade your Heroku dynos to Hobby

This is required to upload SSL certificates.

Upload the certificate to Heroku

sudo heroku certs:add /etc/letsencrypt/live/your_custom_domain/fullchain.pem /etc/letsencrypt/live/your_custom_domain/privkey.pem

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 .

Backend deployed
backend server
https://devcenter.heroku.com/articles/custom-domains#add-a-wildcard-domain
https://devcenter.heroku.com/articles/custom-domains#configuring-dns-for-wildcard-domains
https://certbot.eff.org/
https://mxtoolbox.com/SuperTool.aspx
https://devcenter.heroku.com/articles/ssl#manually-uploading-certificates-and-intermediaries
The Heroku CLI | Heroku Dev Centerherokudevcenter
Logo