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.tomlready 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
- Go to railway.com and create a new project
- Select Deploy from GitHub repo
- Choose your Eden Stack repository
- Railway will detect the monorepo structure
Step 2: Configure the Service
Railway auto-detects the railway.toml in apps/api/. Configure the service:
- Click on the service and go to Settings
- Set the Root Directory to
apps/api - The
railway.tomlhandles the rest:
[build]
builder = "nixpacks"
buildCommand = "bun install --frozen-lockfile"
[deploy]
startCommand = "bun run start"
healthcheckPath = "/health"
healthcheckTimeout = 100
restartPolicyType = "on_failure"
restartPolicyMaxRetries = 3Step 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 upStep 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/healthYou 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.appRedeploy your web app to pick up the change.
Custom Domain
- Go to Settings > Networking > Public Networking
- Click Generate Domain or add a custom domain
- 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 logsScaling
Railway scales automatically based on traffic. For manual control:
- Go to Settings > Scaling
- Adjust vCPU and Memory as needed
- Enable Horizontal Scaling for multiple instances
Environment-Specific Deployments
Create separate environments for staging and production:
- Go to Environments in project settings
- Create
stagingandproductionenvironments - 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
- Deploy to Vercel - Deploy the web frontend
- Background Jobs - Set up Inngest for production
Full documentation for Eden Stack users
This documentation is exclusively available to Eden Stack customers. Already purchased? Log in to access the full content.