My understanding of your question is that you have one Git repository that contains two completely separate programs: one API server and one web server.
Given this assumption, here is what you want to do, step by step:
- Go to the project folder.
- Define the
Procfile
at the root of your project. This will tell Heroku how to start your web server and your API server.
Here's how you can make your Procfile
look like (example):
web: node web/index.js api: node api/index.js
In my example above: I define two types of Heroku speakers: one is called web
and one is called api
. For each of them, you need to tell Heroku which command to run in order to start the corresponding server. In this example, I ran node web/index.js
to start my site, and node api/index.js
to start the API service.
Create two new Heroku apps. You can do this by running heroku create <desired-app-name> --remote <desired-app-name>
several times. NOTE The --remote
flag tells Heroku to create a Git remote for each of your applications in the same repo.
You will then need to tell Heroku about running your actual web application in one Heroku application and your API service in another Heroku application. You can do this using the Heroku CLI:
$ heroku ps:scale web=1 --remote webserver-app-name $ heroku ps:scale api=1 --remote apiserver-app-name
These teams will:
- Launch one web diner for your Heroku app web server.
- Launch one API for your Apacheer Heroku application.
As you can see above, using the ps:scale
command, you can control what types of Heroku commands will be executed from your Procfile
, and how many instances of each of them you would like to have.
Hope this helps!
source share