Deploying MERP25 ERP to Railway.com¶
This guide walks you through deploying the MERP25 ERP system to Railway using its multi-service capabilities.
Architecture Overview¶
You'll create two separate services on Railway from the same repository: 1. Backend: Web Service (Python/Django) 2. Frontend: Static Site (React/Vite)
Step 1: Deploy Backend (Web Service)¶
1.1 Create New Service¶
- Go to Railway Dashboard
- Click "New Project" → "Deploy from GitHub repo"
- Connect your repository.
- Once added, go to the service settings:
- Service Name:
merp25-backend - Root Directory:
backend - Build Command:
./build.sh - Start Command:
gunicorn config.wsgi:application
1.2 Set Environment Variables¶
Add these variables in the Variables tab:
| Variable | Value |
|---|---|
DATABASE_URL |
Your PostgreSQL connection string (Supabase or Railway DB) |
SUPABASE_URL |
Your Supabase project URL |
SUPABASE_KEY |
Your Supabase anonymous key |
ALLOWED_HOSTS |
merp25-backend.up.railway.app,merp25-frontend.up.railway.app |
CSRF_TRUSTED_ORIGINS |
https://merp25-frontend.up.railway.app |
DEBUG |
False |
SECRET_KEY |
(generate a random string) |
Step 2: Deploy Frontend (Static Site)¶
2.1 Create New Service¶
- In the same project, click "New" → "GitHub Repo" (choose the same repo).
- Configure the new service:
- Service Name:
merp25-frontend - Root Directory:
frontend - Build Command:
npm install && npm run build - Install Command:
npm install
2.2 Set Environment Variables¶
Add these variables to the frontend service:
| Variable | Value |
|---|---|
VITE_API_URL |
Your backend service URL (e.g., https://merp25-backend.up.railway.app/api) |
VITE_SUPABASE_URL |
Same as backend |
VITE_SUPABASE_ANON_KEY |
Same as backend |
Step 3: Optimization & Monorepo Setup¶
To prevent the backend triggering a build when you only change frontend files (and vice versa), you must configure Watch Paths.
3.1 Configure Trigger Paths¶
- Go to your Backend Service settings:
- Scroll to Deployments or Triggers section.
- Find Watch Paths (sometimes under "Build & Deploy" or "Git").
- Set the Watch Path to:
/backend/** -
Save.
-
Go to your Frontend Service settings:
- Find Watch Paths.
- Set the Watch Path to:
/frontend/** - Save.
Result:
- When you push changes to frontend/src/..., only the Frontend service will rebuild.
- When you push changes to backend/core/..., only the Backend service will rebuild.
Step 4: Verification¶
- Verify the backend API is reachable at
https://your-backend-url/api/. - Verify the frontend loads the login page.
- Check the browser console to ensure there are no CORS or CSRF errors during login/signup.
Troubleshooting¶
CSRF Failure on Admin Login¶
If you get a "CSRF verification failed" error when logging into /admin, ensure CSRF_TRUSTED_ORIGINS includes the backend's own domain as well as the frontend's domain.
Static Files Not Loading¶
The backend uses whitenoise to serve static files. Ensure python manage.py collectstatic --no-input runs during the build (it is included in backend/build.sh).