Skip to content

Railway Deployment

Note: This guide is for developers and administrators setting up the FG API platform. End users don't need to deploy anything - they can use the platform directly.

This guide covers deploying your FG API backend to Railway.

What is Railway?

Railway is a cloud platform that makes it easy to deploy and manage applications. It provides:

  • Automatic deployments from Git

  • Built-in PostgreSQL databases

  • Environment variable management

  • Automatic HTTPS and custom domains

Deployment Steps

1. Connect Your Repository

  1. Go to Railway.app
  2. Sign up or log in
  3. Click "New Project"
  4. Select "Deploy from GitHub repo"
  5. Choose your FG API repository
  6. Select the server folder as the root directory

2. Configure Environment Variables

In your Railway project dashboard:

  1. Go to "Variables" tab
  2. Add the following environment variables:
bash
NODE_ENV=production
DATABASE_URL=postgresql://user:password@host:port/database
JWT_SECRET=your-strong-jwt-secret-key-here
REFRESH_TOKEN_SECRET=your-refresh-token-secret-key-here
REGISTRATION_APPROVAL_CODE=your-approval-code-here
CLOUDFLARE_PAGES_URL=https://your-frontend-domain.com

3. Set Up Database

  1. In Railway dashboard, click "New"
  2. Select "Database""PostgreSQL"
  3. Railway will automatically provide the DATABASE_URL
  4. Copy the database URL to your environment variables

4. Deploy

  1. Railway will automatically deploy when you push to your repository
  2. Check the "Deployments" tab for deployment status
  3. Your API will be available at the provided Railway URL

Environment Variables

Required Variables

VariableDescriptionExample
NODE_ENVEnvironment modeproduction
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@host:port/db
JWT_SECRETSecret for JWT tokensyour-strong-secret
REFRESH_TOKEN_SECRETSecret for refresh tokensyour-refresh-secret
REGISTRATION_APPROVAL_CODECode for user registrationAPPROVAL123

Optional Variables

VariableDescriptionExample
CLOUDFLARE_PAGES_URLFrontend URL for CORShttps://your-frontend.com
CLIENT_URLAlternative client URLhttps://your-frontend.com
RAILWAY_STATIC_URLRailway static URLhttps://your-app.railway.app

Custom Domain

Setting Up Custom Domain

  1. In Railway dashboard, go to "Settings"
  2. Click "Domains"
  3. Add your custom domain
  4. Update DNS records as instructed
  5. Railway will automatically provision SSL certificate

DNS Configuration

Add these DNS records to your domain:

Type: CNAME
Name: api (or subdomain of choice)
Value: your-app.railway.app

Monitoring and Logs

Viewing Logs

  1. Go to "Deployments" tab
  2. Click on latest deployment
  3. View real-time logs
  4. Check for errors and warnings

Health Checks

Railway automatically monitors your application:

  • HTTP health checks

  • Automatic restarts on failure

  • Performance monitoring

Troubleshooting

Common Issues

Database Connection Errors

  • Check DATABASE_URL environment variable

  • Ensure database is running

  • Verify connection string format

CORS Errors

  • Add frontend URL to CLOUDFLARE_PAGES_URL

  • Check CORS configuration in code

  • Verify environment variables

Authentication Errors

  • Check JWT_SECRET and REFRESH_TOKEN_SECRET

  • Ensure secrets are strong and unique

  • Verify token configuration

Getting Help

  • Check Railway documentation

  • Review deployment logs

  • Contact Railway support

  • Check FG API documentation