My understanding of your question is that you have one Git repository, that contains two entirely separate programs: one API server, and one web server.
With this assumption in mind, here's what you'll want to do, step-by-step:
- Go into your project folder.
- Define a
Procfile
at the root of your project. This will tell Heroku how to run your web server and your API server.
Here's how you might want your Procfile
to look (an example):
web: node web/index.js
api: node api/index.js
In my example above: I'm defining two types of Heroku dynos -- one called web
and one called api
. For each one, you'll need to tell Heroku what command to run to start the appropriate server. In this example, I would run node web/index.js
to start up my website, and node api/index.js
to start up my API service.
Create two new Heroku applications. You can do this by running heroku create <desired-app-name> --remote <desired-app-name>
multiple times. NOTE: The --remote
flag will tell Heroku to create a Git remote for each of your applications in the same repo.
Next, you'll need to tell Heroku to run your actual web application on one Heroku app, and your API service on another Heroku app. You can do this by using the Heroku CLI:
$ heroku ps:scale web=1 --remote webserver-app-name
$ heroku ps:scale api=1 --remote apiserver-app-name
These commands will:
- Run a single web dyno for your webserver Heroku app.
- Run a single API dyno for your apiserver Heroku app.
As you can see above, using the ps:scale
command you can control what types of commands Heroku will run from your Procfile
, and how many instances of each you'd like to have.
Hopefully this helps!
git push heroku-api master
andgit push heroku-web master
to push my master branch to each separate heroku app? – Johannejohannes