Deploy API to Railway

Deploy your Elysia API server to Railway

Deploy API to Railway

This guide walks you through deploying the Elysia API server to Railway.

Why Railway?

  • Zero-config Bun support - Nixpacks auto-detects Bun
  • Pre-configured - The API includes a railway.toml ready to go
  • Great DX - Git-push deploys, excellent dashboard
  • Monorepo friendly - Perfect for Eden Stack's structure

Prerequisites

  • A Railway account
  • Your Neon database URL
  • Git repository connected to Railway

Step 1: Connect Repository

  1. Go to railway.com and create a new project
  2. Select Deploy from GitHub repo
  3. Choose your Eden Stack repository
  4. Railway will detect the monorepo structure

Step 2: Configure the Service

Railway auto-detects the railway.toml in apps/api/. Configure the service:

  1. Click on the service and go to Settings
  2. Set the Root Directory to apps/api
  3. The railway.toml handles the rest:
[build]
builder = "nixpacks"
buildCommand = "bun install --frozen-lockfile"
 
[deploy]
startCommand = "bun run start"
healthcheckPath = "/health"
healthcheckTimeout = 100
restartPolicyType = "on_failure"
restartPolicyMaxRetries = 3

Step 3: Set Environment Variables

In the Railway dashboard, go to Variables and add:

# Required
DATABASE_URL=postgresql://...
BETTER_AUTH_SECRET=your-32-char-secret
BETTER_AUTH_URL=https://your-web-app.vercel.app
CORS_ORIGIN=https://your-web-app.vercel.app
 
# Optional (add as needed)
STRIPE_SECRET_KEY=sk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
RESEND_API_KEY=re_...
OPENAI_API_KEY=sk-...
INNGEST_EVENT_KEY=...
INNGEST_SIGNING_KEY=...

Tip: Use Railway's Variable References to share variables between services (e.g., ${{web.PUBLIC_URL}}).

Step 4: Deploy

Railway deploys automatically on git push. You can also:

# Install Railway CLI
npm install -g @railway/cli
 
# Login
railway login
 
# Link to your project
railway link
 
# Manual deploy
railway up

Step 5: Verify

Once deployed, Railway provides a public URL like your-app-api.up.railway.app.

Test the health endpoint:

curl https://your-app-api.up.railway.app/health

You should see:

{ "status": "ok" }

Step 6: Connect Web App

Update your web app's environment to point to the deployed API:

# In your Vercel project settings or .env.production
VITE_API_URL=https://your-app-api.up.railway.app

Redeploy your web app to pick up the change.

Custom Domain

  1. Go to Settings > Networking > Public Networking
  2. Click Generate Domain or add a custom domain
  3. Update DNS records as instructed

Monitoring

Railway provides built-in monitoring:

  • Logs - Real-time log streaming in dashboard
  • Metrics - CPU, memory, and network usage
  • Deployments - History with rollback support

View logs via CLI:

railway logs

Scaling

Railway scales automatically based on traffic. For manual control:

  1. Go to Settings > Scaling
  2. Adjust vCPU and Memory as needed
  3. Enable Horizontal Scaling for multiple instances

Environment-Specific Deployments

Create separate environments for staging and production:

  1. Go to Environments in project settings
  2. Create staging and production environments
  3. Each environment has its own variables and deployments

Troubleshooting

Build Fails

Check that apps/api/package.json has a start script:

{
  "scripts": {
    "start": "bun run src/index.ts"
  }
}

Health Check Fails

Ensure your API has a /health endpoint:

app.get('/health', () => ({ status: 'ok' }));

Connection Issues

Verify CORS_ORIGIN matches your web app's domain exactly.

Next Steps

Full documentation for Eden Stack users

This documentation is exclusively available to Eden Stack customers. Already purchased? Log in to access the full content.