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
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
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
Onward to the front end!
- Create a new react app and name it using this command.
npx create_react_app client
- 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
- In the package.json file above our "private" and "dependencies" sections we will add
"proxy": "http://localhost:3000"
- In our scripts we will change "start": "react-scripts start" to
"start": "PORT=4000 react-script start"
- We now need to add another package.json into the root of our directory run
heroku buldpacks:add heroku/nodejs --index 1
- Update the package.json by running the commands
git add .
git commit -m ""
git push heroku main
Your fullstack application is now ready for testing!
Top comments (0)