If you've already deployed your Java Spring Boot backend to Railway, congratulations — the hardest part is done! ๐
Now it’s time to deploy your React frontend. Compared to the backend, this will be a breeze. In this guide, I’ll walk you through the entire process of pushing your frontend to GitHub and deploying it to Railway — step-by-step.
๐งฑ Project Structure Recap
Your project likely looks something like this:
Your API is already live at something like:https://todo-production-40cc.up.railway.app/api/todos
✅ Step 1: Update API Route in React
Open your /frontend/src/App.js
file and update the API URL:
const API_URL = "https://todo-production-40cc.up.railway.app/api/todos";
Replace the old "http://localhost:8080"
value to point to your deployed backend.
✅ Step 2: Prepare React App for Deployment
Inside your frontend
folder:
Remove the .git folder
Push the changes to github using the following commands:
git rm --cached frontend
git add frontend
git commit -m "Fix: add frontend as regular folder"
git push origin main
✅ Step 3: Deploy Frontend on Railway
-
Go to Railway
-
Click “New Project”
-
Choose “Deploy from GitHub Repo”
-
Select your todo repository
-
When prompted for project settings:
-
Root directory:
frontend
-
Install command:
npm install
-
Build command:
npm run build
-
Start command:
npx serve -s build
-
(Optional): Predeploy command:
npm install -g serve
-
-
Click Deploy ๐
✅ Step 4: Fix the Port (IMPORTANT)
By default, serve
runs on port 8080, but Railway expects port 3000 unless you say otherwise.
Fix:
-
Go to your project > Settings
Generate the domain.
-
Use: PORT = 8080 when asked.
Save. Railway will redeploy.
You should see your React To-Do app, fully functional and connected to your backend!
You may check out my live todo web app at:
https://optimistic-creativity-production-e88d.up.railway.app/