This is not an overview of deploying a Rails API/React application, built in two separate pieces, two separate repos, to Heroku. (Although I did write a series on the topic.)
This is an overview of taking Rails application that uses Webpack to configure the frontend to use React and deploying it to Heroku. (Which is how I'm building my social media marketing app.) One repo, one app deployed, all the awesomeness.
If you've started your project by running:
rails new rails_react_app -d=postgresql --webpack=react
This overview is for you!
First you'll need to create a new app in your Heroku account, either via the CLI or the web app. Creating an app in the CLI will automatically create a git remote. You can push changes to this remote or set up automatic deploys via GitHub.
$ heroku create rails-react-app
From within the web app:
- New > Create New App: rails-react-app
To set up automatic deploys from GitHub:
- Deployment Method > Connect to GitHub
- Find your project GitHub repo
- Pick the appropriate branch
- Enable Automatic deploys
So far, so good. At this point, we come to the main difference in deployment of separate Rails & React project repos: buildpacks!
You did not use
create-react-app to build this project, so do not need the create-react-app buildpack.
You need to add the Heroku NodeJS and Ruby buildpacks. You can do so via the web app or the CLI.
- Select your project
- Navigate to Settings
- Scroll down to Buildpacks
- Add buildpack: nodejs
- Add buildpack: ruby
$ heroku buildpacks:set heroku/nodejs $ heroku buildpacks:add --index 2 heroku/ruby
To make sure you've added them both successfully:
$ heroku buildpacks
Note, if you get the following errors when running heroku commands:
› Error: Missing required flag: › -a, --app APP app to run command against › See more help with --help
Make sure you're running the commands with the -a flag, followed by the name of your app on Heroku.
$ heroku buildpacks -a rails-react-app
Don't forget to migrate and seed your database!
$ heroku run rake db:migrate $ heroku run rake db:seed
You should be good to go! If you run into any errors, check your logs:
$ heroku logs -t
For me, I needed to upgrade my Ruby version to 2.6.6 to work with Heroku-18.