DEV Community

Cover image for Fullstack Deploy React / Rails / Heroku
Ben Limpic
Ben Limpic

Posted on

Fullstack Deploy React / Rails / Heroku

Here is a short but hopefully comprehensive explanation of deploying a simple React/Rails application on Heroku

  • First, we need to be running a version of Ruby that Heroku will accept; one suggestion is running it on
-v ruby 2.7.4
Enter fullscreen mode Exit fullscreen mode
  • Once we have verified our Ruby version, we can generate our new rails application using PostgreSQL as the database.

  • At this stage, we will begin building out our necessary seed data and migrations.

  • Before we can Seed and Migrate our Db, we must use rails db:create to create our PostgreSQL database.

The following command will install the Linux and Ruby Platforms for our Heroku Application.

bundle lock --add-platform x86_64-linux --add-platform ruby
Enter fullscreen mode Exit fullscreen mode
  • Now we can perform our git add and commit actions.

  • Open the browser window by running heroku open in our terminal.

  • Finally, we will migrate and seed our Heroku Db by running heroku run

rails db:migrate db:seed
Enter fullscreen mode Exit fullscreen mode

Onward to the front end!

  • Create a new react app and name it using this command.
npx create_react_app client
Enter fullscreen mode Exit fullscreen mode
  • Next, we need to install a prefix client to create a unified version of our react app in the client/build folder.
npm install --prefix client
Enter fullscreen mode Exit fullscreen mode
  • In the package.json file above our "private" and "dependencies" sections we will add
"proxy": "http://localhost:3000" 
Enter fullscreen mode Exit fullscreen mode
  • In our scripts we will change "start": "react-scripts start" to
"start": "PORT=4000 react-script start"
Enter fullscreen mode Exit fullscreen mode
  • We now need to add another package.json into the root of our directory run
heroku buldpacks:add heroku/nodejs --index 1
Enter fullscreen mode Exit fullscreen mode
  • Update the package.json by running the commands
git add .
git commit -m ""
git push heroku main
Enter fullscreen mode Exit fullscreen mode

Your fullstack application is now ready for testing!

Top comments (0)