Skip to content

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

  1. Go to Railway Dashboard
  2. Click "New Project""Deploy from GitHub repo"
  3. Connect your repository.
  4. Once added, go to the service settings:
  5. Service Name: merp25-backend
  6. Root Directory: backend
  7. Build Command: ./build.sh
  8. 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

  1. In the same project, click "New""GitHub Repo" (choose the same repo).
  2. Configure the new service:
  3. Service Name: merp25-frontend
  4. Root Directory: frontend
  5. Build Command: npm install && npm run build
  6. 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

  1. Go to your Backend Service settings:
  2. Scroll to Deployments or Triggers section.
  3. Find Watch Paths (sometimes under "Build & Deploy" or "Git").
  4. Set the Watch Path to: /backend/**
  5. Save.

  6. Go to your Frontend Service settings:

  7. Find Watch Paths.
  8. Set the Watch Path to: /frontend/**
  9. 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

  1. Verify the backend API is reachable at https://your-backend-url/api/.
  2. Verify the frontend loads the login page.
  3. 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).