# Migrate Vercel app: Next.js

## Summary

Move a Next.js app's compute from Vercel to Ample. Server-rendered apps run with next build and next start; static exports are published as static sites; environment variables move with --env; a PostgreSQL database can be supplied by URL or auto-provisioned. Cutover is a DNS change with ample domain, and Vercel stays untouched until you confirm.

## Infrastructure requirements

- **Compute:** verified (Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.)
- **Postgres:** verified (Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.)

## Prerequisites

- The Next.js source and its environment variable names and values
- next start bound to 0.0.0.0 on PORT (Vercel does not require this; Ample does)
- A component inventory: edge middleware, ISR, image optimization, cron and Vercel-specific integrations are not migrated by this recipe
- An Ample account token with servers:write, databases:read and domains:write for cutover

## Exact tested configuration

- **template:** `node-22`
- **runtime:** `node`
- **size:** `s-1vcpu-1gb`
- **install:** `npm install`
- **build:** `npm run build --if-present`
- **start:** `npm run start`

## Steps

1. **Inventory.** List what the app uses on Vercel. Compute and environment variables are in scope; edge middleware, ISR revalidation, image optimization, cron jobs and Vercel integrations are out of scope and must be reviewed.
2. **Deploy to Ample in parallel.** Deploy the same source with its environment variables; Vercel keeps serving production.
   
   ```
   ample deploy . --name <app-name> --public --env KEY=value
   ```
3. **Validate on the Ample URL.** Run the app's smoke tests and the success checks; compare responses with production.
4. **Cut over DNS.** Add the custom domain and set the documented DNS records; TLS is issued automatically. Keep Vercel until traffic is verified.
   
   ```
   ample domain add <domain> --app <app-name>
   ```
5. **Rollback.** Point DNS back to Vercel. Nothing on Vercel was changed by this recipe.

## Tested examples

- **Static export canary** (tests/deploy-canaries/next-static-export): Vercel-style static export served with correct 404 handling.
- **SSR canary** (tests/deploy-canaries/next-basic-ssr): next build and next start.
- **Next.js + pg canary** (tests/deploy-canaries/next-postgres-basic): Database connection from a route handler with an auto-provisioned managed database.

## Success checks

- Page renders on the Ample URL (`/` on the live URL, expect ample canary next basic ssr)
- Database route reports a live connection (`/api/db` on the live URL, expect postgres=ok)

## Limitations

- Verified on the node-22 template at s-1vcpu-1gb; other templates and sizes are not verified by this recipe.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- Apps auto-pause when idle and wake on the next request; always-on is an operator setting, not a plan feature.
- Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.
- Apps and their managed databases are placed together; cross-node shared databases are unsupported.
- Documentation only: the catalog does not execute the migration; each stage is a normal authenticated deploy or domain command.
- Edge middleware, ISR, image optimization, cron and Vercel integrations are not verified on Ample and are not migrated.
- Vercel-side changes and deletion are the user's separate actions.

## Cost estimate

Estimated 10.00 USD per month (size prices from pricing.toml at build revision a1b8c38919e59cd035ebabaced73cf84ece24371).
- app server x1 `s-1vcpu-1gb`: 5.00 USD
- managed PostgreSQL database x1 `s-1vcpu-1gb`: 5.00 USD

Apps and managed databases auto-pause when idle; the estimate is the always-on monthly price of the tested sizes. Plan quotas and budgets apply.

## Verification evidence

- canary_run on 2026-09-19T23:55:33Z at revision `1764076-tls-account-903d345`: Next.js static export (Vercel-style output) was published and served, including a nested route and a correct 404. (expires 2027-03-18T23:55:33Z)
- canary_run on 2026-09-19T23:55:33Z at revision `1764076-tls-account-903d345`: Next.js 15 SSR app (next build, next start) deployed on node-22; the page and an API route served correctly. (expires 2027-03-18T23:55:33Z)
- canary_run on 2026-09-20T01:42:25Z at revision `199ff1dfd52683832ae75d3f98b53a7a4bff7f96-dirty (CLI e3181f5)`: Next.js 15 route handler using pg with no DATABASE_URL supplied: Ample auto-provisioned a managed PostgreSQL database and /api/db reported postgres=ok. (expires 2027-03-19T01:42:25Z)

Last verified: 2026-09-20T01:42:25Z

## Execution binding

No execution binding. This recipe is documentation only; nothing is executed automatically.
