Heroku makes it simple for us to manage our domains and subdomains from the CLI. In this recipe, we'll learn the steps to add and remove domains from the command line.
To start, let's open up a new terminal and navigate to one of our Heroku applications. We can add --app application-name
to the end of any of the following commands to run them for a specific application:
First, let's list our application's existing domains:
$ heroku domains === demo-app Domain Names demo2.example.org example.com
Next, let's try to add a custom domain to our application. We can do this with the
domains:add
command:$ heroku domains:add example-domain.com
We can add subdomains using the same command. Refer to the following example:
$ heroku domains:add testing.example-domain.com
If we want to avoid adding subdomains one by one, we can use a wildcard:
$ heroku domains:add *.example-domain.com
Removing an existing domain is simple. Let's try this now:
$ heroku...