Dyrected
Deployment

Railway Deployment

Deploy a self-hosted Dyrected app to Railway with a managed Postgres database.

Railway is a good fit for self-hosted Dyrected deployments — it provides a managed Postgres database, automatic deploys from GitHub, and persistent volumes if you need local file storage.


Prerequisites

  • A Railway account at railway.app
  • Your Dyrected app in a GitHub repo (Next.js or Nuxt)
  • Postgres adapter configured: @dyrected/db-postgres

1. Create a new Railway project

  1. Go to the Railway dashboard → New Project
  2. Select Deploy from GitHub repo and connect your repo
  3. Railway detects the framework and sets up the build automatically

2. Add a Postgres database

  1. Inside your project, click NewDatabaseAdd PostgreSQL
  2. Railway provisions a Postgres instance and injects DATABASE_URL into your app's environment automatically

3. Set environment variables

Go to your service → Variables and add:

VariableValue
DATABASE_URLAuto-set by Railway when you add Postgres
DYRECTED_JWT_SECRETA long random string (32+ chars)
DYRECTED_API_KEYYour server-side API key
NEXT_PUBLIC_DYRECTED_URLhttps://your-app.up.railway.app/dyrected

For file uploads, also add your S3 or Cloudinary credentials — Railway's filesystem is ephemeral, so LocalStorageAdapter won't persist between deploys.


4. Configure your app for production

Make sure your Next.js config handles the DATABASE_URL Railway provides:

// dyrected.config.ts
import { PostgresAdapter } from '@dyrected/db-postgres'

export default defineConfig({
  db: new PostgresAdapter({
    url: process.env.DATABASE_URL!,
  }),
  // ...
})

5. Deploy

Railway automatically deploys on every push to your connected branch. To trigger a manual deploy: DeploymentsDeploy Now.

Watch the build logs — the first deploy runs database migrations automatically when createDyrectedApp(config) initialises.


6. Custom domain

  1. Go to your service → SettingsDomains
  2. Click Add Domain and enter your domain
  3. Add the CNAME record Railway provides to your DNS
  4. Update NEXT_PUBLIC_DYRECTED_URL to use your custom domain

Persistent file uploads

If you need local file storage (not recommended for production), add a Railway volume:

  1. Service → VolumesAdd Volume
  2. Mount path: /app/public/uploads
  3. Set LocalStorageAdapter path to ./public/uploads in your config

For anything beyond a single instance, use S3 or Cloudinary — see Storage Adapters.


Health check

Add a health endpoint Railway can ping to verify the app is running:

// app/api/health/route.ts
export async function GET() {
  return Response.json({ ok: true })
}

Then in Railway: Service SettingsHealth Check Path/api/health.

On this page