Vercel
This page is for operators who deploy their own fork of Adiutor on Vercel. It covers what differs from other hosts, the databases and settings each environment needs, what vercel.json does, following releases, the background jobs, fork pull requests and rolling back.
What differs on Vercel
Section titled “What differs on Vercel”- No local disk for files. Choose an S3-compatible bucket or an SFTP folder: see File storage. The local folder storage is refused on Vercel.
- Files up to 4 MB. Vercel refuses larger request bodies, so the largest file can’t be set above 4 MB.
- Functions stop after 60 seconds.
- The jobs need a schedule, because no process of yours keeps running. See Start the background jobs.
- The client’s address works as it is. Vercel replaces
X-Forwarded-Forwith the client’s address. See Reverse proxy.
Everything else is the same.
To set up:
- Fork the repository, and import your fork in Vercel.
- Add a database. Neon, through Vercel’s integration, works: it gives a pooled
DATABASE_URLand a directDATABASE_URL_UNPOOLEDfor migrations. - Set the settings for each environment.
- Deploy. Each build migrates the database first (What vercel.json does).
- Follow First run right away, and start the background jobs.
A database per environment
Section titled “A database per environment”Preview must never share Production’s database. Preview migrates on every build of main: sharing would put each migration into production before its release, and the live release would run against a schema it doesn’t know.
- Turn on the Neon integration’s branch for preview deployments, or
- connect the integration to Production only, create a
previewbranch in Neon, and setDATABASE_URL(pooled) andDATABASE_URL_UNPOOLEDfor Preview yourself.
Check that Preview’s database host differs from Production’s.
Settings per environment
Section titled “Settings per environment”In Settings › Environment Variables, give each environment its own:
BETTER_AUTH_URL: the environment’s own address, or sign-in links and redirects point at the other one.BETTER_AUTH_SECRET: a random secret of at least 32 characters.CRON_SECRET: a different random secret per environment, at least 32 characters (openssl rand -base64 32), for the jobs’ endpoint.- Sign-in provider credentials, only where the callback addresses are registered with the provider: see Sign-in providers. Leave them unset in Preview otherwise.
- The mail server and the file storage: see Email and File storage.
What vercel.json does
Section titled “What vercel.json does”vercel.json is strict JSON, so it can’t hold comments. Its build settings take precedence over the same fields in the project’s dashboard.
- What’s built. Every commit on
mainis built, except one that changes onlysites/(the website and the guide, which Vercel doesn’t serve). Onproduction, only a release commit is built (its first line starts withchore(main): release). Every other branch is skipped. - Each build migrates first. On
mainandproduction,pnpm db:migrateruns beforepnpm build, throughDATABASE_URL_UNPOOLEDor elseDATABASE_URL. When migrating fails, the build fails and the previous deployment stays live. - A tick every 15 minutes. A Vercel schedule (
jobs-tick, Vercel Schedules, in beta) callsGET /api/jobs, withAuthorization: Bearerand the environment’sCRON_SECRET. On the Hobby plan it runs somewhere within each 15 minutes. It’s the fallback for the external cron service below. Preview’s copy starts inactive: leave it so. On the Pro plan you can change it to*/5 * * * *, and the external service becomes optional.
Following releases
Section titled “Following releases”To have Production follow releases and Preview follow main:
-
In Settings › Environments › Production, set the Production branch to
production. Until that branch exists, Production keeps its current deployment. -
In a checkout of your fork, fetch the releases’ tags from Adiutor’s repository, and push the release you want to your fork’s
productionbranch:Terminal window git remote add upstream https://github.com/bastolen/adiutor.gitgit fetch upstream --tagsgit push origin v0.5.0^{commit}:refs/heads/productionThe tag points at the release commit (its first line starts with
chore(main): release), sovercel.jsonbuilds it. Writerefs/heads/productionin full: pushing a tag to a plainproductionwould create a tag of that name the first time, not the branch. For a later release, push its tag the same way.
main is then Preview. A push of anything but a release commit to production is skipped, so a stray push never reaches production. Give main a fixed address under Settings › Domains, with Git Branch set to main.
Start the background jobs
Section titled “Start the background jobs”Use an external cron service (such as cron-job.org), one entry per environment, every 5 minutes:
GET https://<the environment's address>/api/jobs- The header
Authorization: Bearer <that environment's CRON_SECRET> - For Preview with Deployment Protection on, also the header
x-vercel-protection-bypasswith the secret from Settings › Deployment Protection › Protection Bypass for Automation. That secret also gives deploymentsVERCEL_AUTOMATION_BYPASS_SECRET, which the endpoint uses to continue a tick on itself, so a backlog doesn’t wait for the next tick. - Have the service warn you when the answer isn’t 200: a 500 means a job failed.
Logs › Jobs then shows a recent tick. After 45 minutes without one, the dashboard and the Jobs page warn staff Admins and Managers that background jobs aren’t running. See Background jobs.
Pull requests from forks
Section titled “Pull requests from forks”Keep Git Fork Protection on (Project Settings › Git). A fork brings its own vercel.json, so nothing else can stop its builds. Never authorise the deployment of a fork’s pull request: it would run with the Preview environment’s secrets.
Rolling back
Section titled “Rolling back”Use Vercel’s Instant Rollback. A rolled-back deployment runs against the database as the newer release left it, so check Upgrading before you rely on it.
Example
Section titled “Example”For https://adiutor.dev as Production and a Preview at its own address, each has its own Neon branch, its own CRON_SECRET, and its own cron entry calling /api/jobs every 5 minutes.
Good to know
Section titled “Good to know”- A failed migration keeps the previous deployment live: look at the build log.
- Files are never on Vercel’s disk: set the storage before turning attachments on.
Related
Section titled “Related”Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.
Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).