Railway
Deploy the production image to Railway, configured as code in .railway/railway.ts.
.railway/railway.ts is the service's configuration on Railway, as code. A project with a frontend and its API runs two services: see below. A project without a website runs its API alone: see Without a website.
pnpm clubedge deploy does these steps for you: the project, Postgres, the service, its domain and variables.
What .railway/railway.ts sets
- Build: Railway builds the root
Dockerfile. - Pre-deploy:
node /app/migrate.mjsruns before each release, so a failed migration stops it. - Health check:
/api/health, checked before Railway switches traffic, with a 60-second timeout. - Variables stay managed by
deploy,railway variable set, or the dashboard. SetCLIENT_IP_HEADER=x-real-ipon the public service, where Railway's edge puts each client's address;deploysets it for you (CLI 0.42.0 or newer).
It replaced railway.json, which Railway stops reading on 2026-12-01. The file names the service after the package; if yours has another name, change it there.
Deploy by hand
Add Railway's TypeScript SDK, which the file imports, then apply it once with Railway CLI 5.42.1 or newer:
pnpm add -D -w railway
railway login
railway link # or railway init for a new project
railway config applyAdd Postgres (and Redis with cache redis) to the project, or use your own, then set the production variables on the service and deploy with railway up. Give the service a public domain in its settings, and set NEXT_PUBLIC_APP_URL to it: Railway passes the service's variables to the Docker build.
Background jobs
Railway runs the app as a long-lived server, so the jobs worker runs with it.
A frontend and its API
A project with a frontend and its API runs as two Railway services in one project. pnpm clubedge deploy creates both, and rewrites .railway/railway.ts to describe them:
| Service | Builds | Domain | Health check | Before each release |
|---|---|---|---|---|
<package>-web, the frontend | Dockerfile, port 3000 | A public *.up.railway.app domain | / | Nothing |
<package>-api, the API | apps/api/Dockerfile, port 3001 | None: reached over Railway's private network | /api/health | node /app/migrate.mjs |
Their variables:
- The frontend:
API_URL, which.railway/railway.tssets to the API service's private domain on port 3001, so/apireaches the API privately.PORT=3000, and your auth provider'sVITE_*values: Railway passes the service's variables to the Docker build, which compiles them in. With Better Auth, alsoDATABASE_URL,BETTER_AUTH_SECRET, andBETTER_AUTH_URL(the frontend's domain), since Better Auth runs in the frontend's server. - The API:
DATABASE_URL(a reference to Railway's Postgres, or your own),FRONTEND_URLset to the frontend's domain, your auth provider's server variables, and the variables of the other modules, such asREDIS_URLorSTRIPE_SECRET_KEY.
Stripe's webhook endpoint and Inngest's app URL use the frontend's domain, which forwards them to the API over the private network. With pg-boss or BullMQ, the worker runs inside the API service.
The migrations run in the API's pre-deploy step, so a failed migration stops the API's release. See Production variables for each provider's.
Without a website
A project without a website (Starter v0.28.0 or newer) runs as one Railway service, the API, which clients reach directly. pnpm clubedge deploy creates it, and writes .railway/railway.ts so that Railway builds the API's image:
| Service | Builds | Domain | Health check | Before each release |
|---|---|---|---|---|
<package>-api, the API | apps/api/Dockerfile, port 3001 | A public *.up.railway.app domain | /api/health | node /app/migrate.mjs |
Its variables are the API's: DATABASE_URL, your auth provider's server variables, the other modules' variables, and CLIENT_IP_HEADER=x-real-ip. With Better Auth, which runs in the API, also BETTER_AUTH_SECRET and BETTER_AUTH_URL, the service's public URL. With pg-boss or BullMQ, the worker runs inside it. For the deploy workflow, set RAILWAY_SERVICE to <package>-api.
The deploy workflow
The Deploy job uploads the checkout with railway up --ci: Railway builds the image and runs the pre-deploy migrations. It needs the secret RAILWAY_TOKEN, a project token from the project's settings, and the variable RAILWAY_SERVICE, the service's name. Railway only lets verified (paid) accounts create project tokens; pnpm clubedge deploy works without one, with your Railway login.
With a frontend and its API, the job uploads only the service RAILWAY_SERVICE names; pnpm clubedge deploy releases both.
How is this guide?