Documentation
Deployment
Deploy Motoko Base to any Next.js-compatible platform, with a Vercel walkthrough as the recommended option.
Motoko Base is a standard Next.js application and can be deployed to any platform that supports Next.js — Vercel, Railway, Fly.io, Render, Docker on a VPS, AWS, Cloudflare, or self-hosted Node.
Requirements:
- Node.js ≥ 22
- pnpm (or translate scripts to your package manager)
- Ability to set environment variables at build and runtime
- PostgreSQL reachable from the host
Build and start commands:
pnpm install
pnpm build
pnpm startMigrations run separately (not during next build):
pnpm db:migrateComplete the Production Setup checklist before go-live.
Platform-agnostic steps
- Connect your repo to the host (or deploy a built artifact).
- Set environment variables from Production Setup.
- Run migrations against production Postgres (
pnpm db:migrate— use a direct DB URL if the pooler blocks DDL). - Build:
pnpm build(Node 22+, install deps withpnpm install). - Start:
pnpm start(default port3000— configurePORTif your host requires it). - Configure webhooks — Polar →
{APP_URL}/api/billing/webhooks/polarwhen billing is enabled. - Smoke test — sign up, verify email, open dashboard, test integrations you enabled.
Notes for any host
| Topic | Guidance |
|---|---|
| Serverless / edge | Works — app uses standard App Router + Server Actions. Prefer Postgres pooler for DATABASE_URL. |
| Long-running server | Works — same env vars and commands. |
| Docker | Multi-stage build: install → pnpm build → run pnpm start with production env. |
| Preview/staging | Use separate env vars and OAuth/Polar sandbox credentials; optional BETTER_AUTH_TRUSTED_ORIGINS. |
| Secrets | Never commit .env. Use the host's secret manager. Never expose server secrets on NEXT_PUBLIC_*. |
| Sentry source maps | Set SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT in the build environment. |
Official Next.js deployment guide: nextjs.org/docs/app/getting-started/deploying
Recommended: Vercel
Vercel is the recommended option — zero-config Next.js hosting, preview deployments, and native support for the stack Motoko Base uses.
Vercel docs: vercel.com/docs
1. Import the project
- Push your repo to GitHub, GitLab, or Bitbucket
- Import the project in Vercel
- Framework preset: Next.js (auto-detected)
- Build command:
pnpm build(Vercel detects pnpm frompackageManagerinpackage.json) - Install command:
pnpm install
2. Environment variables
In Project Settings → Environment Variables, add vars from Production Setup:
- Production — all production values
- Preview — staging/sandbox values (Polar sandbox, test OAuth apps, etc.)
At minimum for production:
DATABASE_URL=
BETTER_AUTH_SECRET=
BETTER_AUTH_URL=https://your-app.vercel.app
NEXT_PUBLIC_APP_URL=https://your-app.vercel.app
RESEND_API_KEY=
EMAIL_FROM=Add integration vars as you enable them (Polar, R2, PostHog, Sentry, OAuth, OpenAI).
For Sentry source maps, also set SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT for the Production environment so they are available at build time.
3. Database migrations
Run migrations before the first production deploy (or from CI):
# Locally or CI — point DATABASE_URL at production (direct URL if needed)
pnpm db:migrateVercel does not run migrations automatically. Options:
- Run manually from your machine against production
DATABASE_URL - Add a CI step (GitHub Action) that runs
pnpm db:migrateon deploy - Use Supabase migration tooling if you host Postgres there
4. Deploy
Push to your main branch — Vercel builds and deploys automatically.
After the first deploy:
- Update
BETTER_AUTH_URLandNEXT_PUBLIC_APP_URLto your custom domain if you add one - Update OAuth callback URLs and Polar webhook URL to match the live domain
- Redeploy if env vars changed
5. Custom domain
- Project Settings → Domains → add your domain
- Update DNS per Vercel instructions
- Set
BETTER_AUTH_URLandNEXT_PUBLIC_APP_URLtohttps://yourdomain.com - Update Google/GitHub OAuth and Polar webhook URLs
- Redeploy
6. Verify
- Sign up → receive verification email (Resend)
- Sign in →
/dashboardloads - Optional: Polar checkout, R2 upload, PostHog events in dashboard, Sentry test error (
pnpm build && pnpm startlocally or check Issues after deploy)
Other platforms (brief)
| Platform | Approach |
|---|---|
| Railway | Connect repo, set env vars, build pnpm build, start pnpm start, attach Postgres plugin |
| Fly.io | Dockerfile or fly launch, set secrets via fly secrets set, run migrations via release command |
| Render | Web Service, build pnpm install && pnpm build, start pnpm start |
| Docker | Node 22 image, copy repo, pnpm install --frozen-lockfile && pnpm build, CMD pnpm start |
Same env vars and migration step apply everywhere — only the host configuration differs.
Production Setup — Full pre-launch checklist.
Environment Variables — Complete env reference.