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
- Go to Railway.app
- Sign up or log in
- Click "New Project"
- Select "Deploy from GitHub repo"
- Choose your FG API repository
- Select the
serverfolder as the root directory
2. Configure Environment Variables
In your Railway project dashboard:
- Go to "Variables" tab
- Add the following environment variables:
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.com3. Set Up Database
- In Railway dashboard, click "New"
- Select "Database" → "PostgreSQL"
- Railway will automatically provide the
DATABASE_URL - Copy the database URL to your environment variables
4. Deploy
- Railway will automatically deploy when you push to your repository
- Check the "Deployments" tab for deployment status
- Your API will be available at the provided Railway URL
Environment Variables
Required Variables
| Variable | Description | Example |
|---|---|---|
NODE_ENV | Environment mode | production |
DATABASE_URL | PostgreSQL connection string | postgresql://user:pass@host:port/db |
JWT_SECRET | Secret for JWT tokens | your-strong-secret |
REFRESH_TOKEN_SECRET | Secret for refresh tokens | your-refresh-secret |
REGISTRATION_APPROVAL_CODE | Code for user registration | APPROVAL123 |
Optional Variables
| Variable | Description | Example |
|---|---|---|
CLOUDFLARE_PAGES_URL | Frontend URL for CORS | https://your-frontend.com |
CLIENT_URL | Alternative client URL | https://your-frontend.com |
RAILWAY_STATIC_URL | Railway static URL | https://your-app.railway.app |
Custom Domain
Setting Up Custom Domain
- In Railway dashboard, go to "Settings"
- Click "Domains"
- Add your custom domain
- Update DNS records as instructed
- 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.appMonitoring and Logs
Viewing Logs
- Go to "Deployments" tab
- Click on latest deployment
- View real-time logs
- 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_URLenvironment variableEnsure database is running
Verify connection string format
CORS Errors
Add frontend URL to
CLOUDFLARE_PAGES_URLCheck CORS configuration in code
Verify environment variables
Authentication Errors
Check
JWT_SECRETandREFRESH_TOKEN_SECRETEnsure secrets are strong and unique
Verify token configuration
Getting Help
Check Railway documentation
Review deployment logs
Contact Railway support
Check FG API documentation