cookieScanner.crawl (opt-in) adds "Crawl site" to the Cookie review box. The
site asks the shared scanner service (services/cookie-crawler: Node +
Playwright, Dockerfile, deployed once on Coolify) to crawl its sitemap pages
twice, with no consent and after "Accept all". The service posts cookies,
storage keys and third-party hosts back to POST /api/ipal/cookie-crawl/results
(bearer token, running job only). No browser in the site.
Findings land as drafts through the same merge rules. Anything stored before
consent that is not necessary, and tracker requests before consent, are
violations, flagged on the review entries from the latest crawl only. The
cookie-crawl global keeps the latest result (no history). A dashboard warning
(CookieCrawlAlert) and an opt-in e-mail through the project's mail adapter
follow a crawl with violations or new unknown cookies. Scheduled crawls: a
Coolify scheduled task with the token. ipalEnvRules({ cookieCrawl: true }).
Also: the six older real-Payload tests no longer leave an orphaned
payload generate:types process (typescript.autoGenerate: false).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
468 lines
27 KiB
Markdown
468 lines
27 KiB
Markdown
# Deployment — environment variables and production
|
||
|
||
The single source of truth about environment variables (all of them, what they mean,
|
||
required or not) and how to deploy a project to production consistently. Env is part
|
||
of deployment — the same variables in dev (.env) and in production (the Coolify app).
|
||
|
||
**Every project is deployed with Coolify (v4)** on servers the team runs; the team also runs the DNS
|
||
zones. This page describes that one path (§4); other hosts — a short note at the end of §4.
|
||
Coolify labels below may differ slightly between Coolify versions.
|
||
|
||
Related: [PROGRAMISTA.md](./dev/PROGRAMISTA.md) (from zero to a working site, §4 deployment),
|
||
[env.md](./env.md) (validation at startup), [storage.md](./storage.md) (R2), [email.md](./email.md) (Graph),
|
||
[security.md](./security.md), [integrations.md](./integrations.md) (integration status in the panel).
|
||
|
||
---
|
||
|
||
## 1. ENVIRONMENT VARIABLES — full list
|
||
|
||
### Core (REQUIRED — the project will not start without them)
|
||
|
||
```bash
|
||
# Database (Mongo or Postgres — depending on the project)
|
||
DATABASE_URI=mongodb://... # or postgres://... / file:./dev.db (dev)
|
||
|
||
# Payload secret (signs sessions/tokens) — random, long
|
||
PAYLOAD_SECRET=<random-string-min-32-chars>
|
||
|
||
# Public site URL (canonical, hreflang, OG, manifest)
|
||
NEXT_PUBLIC_SERVER_URL=https://klient.pl # dev: http://localhost:3000
|
||
```
|
||
|
||
### Email — Graph (OPTIONAL, agency-level, when transport = Graph)
|
||
|
||
```bash
|
||
GRAPH_TENANT_ID=<azure-tenant-id>
|
||
GRAPH_CLIENT_ID=<azure-app-client-id>
|
||
GRAPH_CLIENT_SECRET=<azure-app-secret>
|
||
GRAPH_SENDER=[email protected] # shared mailbox
|
||
```
|
||
All 4 are needed. When Graph is selected in the panel and one is missing — `mailAdapter()` sends through
|
||
the SMTP from the panel and reports it in Site Integrations (status `graph-unavailable`). See email.md.
|
||
|
||
### Storage — R2 (OPTIONAL in dev, recommended in production)
|
||
|
||
```bash
|
||
R2_BUCKET=<bucket-name>
|
||
R2_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com
|
||
R2_ACCESS_KEY_ID=<access-key>
|
||
R2_SECRET_ACCESS_KEY=<secret-key>
|
||
R2_PUBLIC_URL= # usually EMPTY: media served through the app (§6, storage.md)
|
||
# or https://media.klient-media.com (custom domain, zone on Cloudflare)
|
||
```
|
||
All 4 keys → R2. None → local disk (a partial set → warning in the log + disk).
|
||
`R2_PUBLIC_URL` empty → files in R2, served by the app at `/api/media/file/<name>`; set →
|
||
URLs point at that domain. Outside production, `R2_PUBLIC_URL` alone → read-only media. See storage.md.
|
||
|
||
### Table — all variables read by the plugin
|
||
|
||
| Variable | Required | Layer | Description |
|
||
|---|---|---|---|
|
||
| `DATABASE_URI` | ✅ | infra | database connection (read by the project config, not the plugin) |
|
||
| `PAYLOAD_SECRET` | ✅ | infra | Payload secret (as above) |
|
||
| `NEXT_PUBLIC_SERVER_URL` | ✅ | infra | public URL (canonical, OG, sitemap, IndexNow) |
|
||
| `NODE_ENV` | ⬜ | infra | `production` tightens `ipalEnvRules` (R2 keys, `IPAL_IP_HEADER`) and turns off read-only media mode |
|
||
| `GRAPH_TENANT_ID` | ⬜ | email | Azure tenant (Graph) |
|
||
| `GRAPH_CLIENT_ID` | ⬜ | email | Azure app id |
|
||
| `GRAPH_CLIENT_SECRET` | ⬜ | email | Azure secret |
|
||
| `GRAPH_SENDER` | ⬜ | email | sender mailbox |
|
||
| `R2_BUCKET` | ⬜ (✅ prod) | storage | R2 bucket |
|
||
| `R2_ENDPOINT` | ⬜ (✅ prod) | storage | R2 S3 endpoint |
|
||
| `R2_ACCESS_KEY_ID` | ⬜ (✅ prod) | storage | R2 key |
|
||
| `R2_SECRET_ACCESS_KEY` | ⬜ (✅ prod) | storage | R2 secret |
|
||
| `R2_PUBLIC_URL` | ⬜ (✅ prod only with `storage: { requirePublicUrl: true }`) | storage | media domain attached to the bucket; empty = media through the app (§6); dev: also the `/media` path |
|
||
| `IPAL_IP_HEADER` | ⬜ (✅ prod) | forms | header with the real IP for the rate limit (`cf-connecting-ip`, `x-forwarded-for`); without it, a warning in the log |
|
||
| `NEXT_PUBLIC_TURNSTILE_SITE_KEY`, `TURNSTILE_SECRET_KEY` | ⬜ | forms | fallback when the Turnstile keys are not in Site Integrations |
|
||
| `INDEXNOW_KEY` | ⬜ | SEO | IndexNow key (takes precedence over the key from the panel) |
|
||
| `IPAL_COOKIE_SCAN_URL`, `IPAL_COOKIE_SCAN_TOKEN` | ⬜ (✅ prod with `ipalEnvRules({ cookieCrawl: true })`) | consent | cookie crawl (`cookieScanner.crawl`): the shared scanner service's URL and this site's token ([cookie-scanner.md](./cookie-scanner.md#browser-crawl)) |
|
||
| `IPAL_NOINDEX` | ⬜ | SEO | `1`/`true`/`yes` **on staging only** — the whole site is noindex (robots, meta, `X-Robots-Tag`) |
|
||
|
||
"✅ prod" = required by `ipalEnvRules({ storage: true })` / `({ ipHeader: true })` with
|
||
`NODE_ENV=production` — as long as the project runs the validation (env.md). The plugin itself does not stop
|
||
startup when these variables are missing.
|
||
|
||
**Rule:** all secrets are agency/infrastructure variables — in `.env`
|
||
(dev) and the Coolify app's Environment Variables (prod, §4.2), NEVER in the repo. Per-project data editable by the
|
||
editor goes to the PANEL (Site Settings, Site Integrations), not to env.
|
||
|
||
### .env.example — always in the repo
|
||
|
||
Every project has a `.env.example` listing the variables (no values/secrets) —
|
||
a template for the next person. Commit it; never commit `.env` (with values).
|
||
|
||
---
|
||
|
||
## 2. BEFORE DEPLOY — checklist
|
||
|
||
- [ ] `pnpm build` (script with `--webpack`, §3) passes LOCALLY (not only dev)
|
||
- [ ] All required env set in the Coolify app, with the right build/runtime availability (§4.2)
|
||
- [ ] `NEXT_PUBLIC_SERVER_URL` = production URL (not localhost), the same host as the Coolify domain you redirect to (§4.1)
|
||
- [ ] `PAYLOAD_SECRET` different from dev (production secret)
|
||
- [ ] Production database (not dev/SQLite); Postgres: migrations run on container start (§4.3)
|
||
- [ ] Health check on `/api/health` set in Coolify (§4.4)
|
||
- [ ] Scheduled database backups to S3/R2 on (§4.6)
|
||
- [ ] HSTS on (buildSecurityHeaders hsts: production)
|
||
- [ ] Media: R2 (served through the app, or a media domain on Cloudflare — §6), or a persistent volume (§4.8)
|
||
- [ ] Media migration local→R2 (if you switch)
|
||
- [ ] Policy pages + cookie banner ([PROGRAMISTA.md §5](./dev/PROGRAMISTA.md))
|
||
- [ ] `IPAL_NOINDEX` NOT set in production
|
||
|
||
---
|
||
|
||
## 3. BUILDING FOR PRODUCTION
|
||
|
||
### Build script (Next 16 + Payload)
|
||
|
||
```json
|
||
// package.json — --webpack REQUIRED (Turbopack conflicts with withPayload)
|
||
"build": "cross-env NODE_OPTIONS=\"--max-old-space-size=3072\" next build --webpack"
|
||
```
|
||
|
||
`--max-old-space-size` — Payload + Next can be memory-hungry during the build;
|
||
3072 MB prevents OOM on smaller machines.
|
||
|
||
### Order: build → migrations → start
|
||
|
||
What Coolify runs (install/build/start commands in the app's build settings):
|
||
|
||
```bash
|
||
pnpm install --frozen-lockfile # exactly from the lockfile (repeatable build)
|
||
pnpm generate:types # types from collections
|
||
pnpm build # --webpack
|
||
# Postgres: pending migrations run when the NEW container starts, before it is healthy (§4.3)
|
||
pnpm start # production server, port 3000
|
||
```
|
||
|
||
---
|
||
|
||
## 3a. Pitfall: metadata in <body> instead of <head> (htmlLimitedBots)
|
||
|
||
Next 16 streams metadata of dynamic pages into `<body>` (moves it to head with a
|
||
JS script). Crawlers without JS see canonical/hreflang/title/favicon outside head →
|
||
SEO loss. **Every project** needs this in next.config:
|
||
|
||
```ts
|
||
const nextConfig: NextConfig = {
|
||
htmlLimitedBots:
|
||
/Googlebot|Google-InspectionTool|Bingbot|Yandex|DuckDuckBot|Screaming Frog|AhrefsBot|SemrushBot/i,
|
||
// ...
|
||
}
|
||
```
|
||
|
||
Check: `curl -A "Googlebot" URL | grep canonical` — it must be in `<head>`.
|
||
Details and symptoms: seo.md (htmlLimitedBots section).
|
||
|
||
## 3a2. ISR — page cache (metadata in head + speed)
|
||
|
||
For content pages (page.tsx) use ISR: `export const revalidate = 3600`.
|
||
It caches the whole page with a finished `<head>` → metadata always in head (not body,
|
||
no streaming race condition), TTFB ~20ms, no 503 (cold start).
|
||
|
||
```ts
|
||
// app/(frontend)/[locale]/[[...slug]]/page.tsx
|
||
export const revalidate = 3600 // 1h; or shorter, or on-demand
|
||
```
|
||
|
||
NOTE: ISR and `force-dynamic` are MUTUALLY EXCLUSIVE. Pages → ISR (revalidate).
|
||
sitemap/robots → force-dynamic (they generate on request). Do not mix them on one
|
||
route. Content from the panel: ISR = the editor waits for revalidation; consider on-demand
|
||
revalidation (`buildRevalidateHook` on collections; plugin globals — `ipalKit({ revalidatePath })`; your own globals —
|
||
`buildGlobalRevalidateHook`). See [seo.md](./seo.md), [hooks.md](./hooks.md).
|
||
|
||
## 3a3. SSG and database access at build time (IMPORTANT for SEO)
|
||
|
||
`generateStaticParams` (from lib/content) prerenders pages as SSG — synchronous
|
||
head, SEO 100/100. BUT to prerender, **the build must have access to the
|
||
database** (generateStaticParams reads pages from the database at build time).
|
||
|
||
- **Build HAS database access** (database reachable from the Coolify build, e.g. on the same
|
||
server/network) → pages prerendered as SSG (`●`), synchronous head → SEO OK ✓
|
||
- **Build has NO access** (isolated build stage) → generateStaticParams returns
|
||
`[]` (the plugin catches the error, the build does not fail), but pages render on-demand
|
||
(dynamically) → head may stream into body → the SEO problem is back ✗
|
||
|
||
`generateStaticParams` covers only the pages collection (max 1000 documents per language) — entries
|
||
of content collections render on-demand (ISR).
|
||
|
||
The plugin protects the build from a CRASH (try/catch → `[]`), but that does NOT replace
|
||
database access. **For full SSG/SEO, make sure the container build can reach the database.**
|
||
|
||
In Coolify: the database (Mongo/Postgres) should be reachable during `pnpm build`,
|
||
not only at runtime — `DATABASE_URI` (and `PAYLOAD_SECRET`) need **Build time** availability (§4.2) and a
|
||
host the build can reach. If the build cannot reach the database's internal host:
|
||
- put the database resource on the same server/network as the app, or
|
||
- build with a `DATABASE_URI` pointing to an address reachable from the build.
|
||
|
||
Check: after the build, `pnpm build` shows routes as `●` (SSG), not `ƒ`
|
||
(Dynamic). If `ƒ` despite generateStaticParams → the build had no database access.
|
||
|
||
## 3b. Pitfall: prerendering database-dependent routes (REQUIRED)
|
||
|
||
By default Next **prerenders** routes like `sitemap.ts` during `next build` —
|
||
it treats them as static. If such a route reads the database (sitemap → Payload →
|
||
Mongo/Postgres), the build **tries to connect to the database**. And the build container
|
||
(Coolify build, CI) often has NO access to the database network → the connection
|
||
fails (`ENOTFOUND`, `MongooseServerSelectionError`) → **the build crashes**.
|
||
|
||
**Fix — `force-dynamic` on database-dependent routes:**
|
||
```ts
|
||
// app/sitemap.ts
|
||
export { sitemap as default } from '@/lib/content'
|
||
export const dynamic = 'force-dynamic' // generate at runtime, not at build time
|
||
```
|
||
|
||
This tells Next: do not prerender at build time, generate at runtime (when the database is
|
||
reachable). It applies to EVERY route that reads the database while rendering:
|
||
- `app/sitemap.ts` → `force-dynamic`
|
||
- other routes/pages reading the database during prerender → consider `force-dynamic` or
|
||
handle the database error (try/catch with a fallback)
|
||
|
||
The plugin also guards the sitemap handler (catches the database error, returns an empty
|
||
map), so the build will not fail even without `force-dynamic` — but that is a safety
|
||
net, not the proper fix. Always add `force-dynamic`.
|
||
|
||
**404 page** (`not-found.tsx`) reading settings from the database — the same problem.
|
||
Wrap `getCachedPayload()` in try/catch so a missing database at build time does not crash
|
||
the 404 prerender (fallback to static texts).
|
||
|
||
**Local check** (simulate a missing database):
|
||
```bash
|
||
DATABASE_URI=mongodb://invalid-host:27017/test pnpm build
|
||
# the build must pass (exit code 0) despite the unreachable database
|
||
```
|
||
|
||
## 4. HOSTING — Coolify
|
||
|
||
One Coolify **application** per project (built from the Git repo) plus a Coolify **database** resource
|
||
(Postgres or Mongo) on the same server. Order of the steps below = order of setting up a new project.
|
||
|
||
### 4.1 Application and domains
|
||
|
||
- **Port** 3000 (`pnpm start`). Do not publish a host port mapping — it disables rolling updates (§4.4).
|
||
- **Domains**: both addresses, e.g. `https://klient.pl,https://www.klient.pl`. Coolify's proxy issues a
|
||
Let's Encrypt certificate per domain (HTTP challenge — DNS must already point at the server, §6 rows 1–3).
|
||
- **Redirect** www ↔ apex in the app's domain/redirect setting (Direction) so the canonical host is the one in
|
||
`NEXT_PUBLIC_SERVER_URL` — canonical, hreflang and sitemap URLs use that variable, the redirect must agree with it.
|
||
|
||
### 4.2 Environment variables — where and when
|
||
|
||
Coolify → the application → **Environment Variables**. Each variable can be available at **build time**,
|
||
at **runtime**, or both (newer versions: two switches *Build time* / *Runtime*; older: a *Build Variable*
|
||
checkbox; default: both). A changed variable takes effect only after a **redeploy** (build-time ones need a rebuild).
|
||
|
||
| Variables | Build time | Runtime | Why |
|
||
|---|---|---|---|
|
||
| `NEXT_PUBLIC_SERVER_URL`, `NEXT_PUBLIC_TURNSTILE_SITE_KEY` (all `NEXT_PUBLIC_*`) | ✅ | ✅ | `next build` inlines them into the client bundle — missing at build = missing in the browser |
|
||
| `DATABASE_URI`, `PAYLOAD_SECRET` | ✅ only if the build prerenders from the database (§3a3), otherwise ⬜ | ✅ | SSG (`generateStaticParams`) needs the database during `pnpm build`; DB-reading routes stay `force-dynamic` either way (§3b) |
|
||
| `R2_*`, `GRAPH_*`, `TURNSTILE_SECRET_KEY`, `INDEXNOW_KEY`, `IPAL_IP_HEADER` | ⬜ | ✅ | read at runtime only — keep secrets out of the build |
|
||
| `NODE_ENV` | — | — | do not set by hand: `next build` / `next start` use `production` |
|
||
| `IPAL_NOINDEX` | — | ✅ staging only | never on production |
|
||
|
||
Multiline values (keys) → mark *Multiline*; values containing `$` → mark *Literal* (otherwise Coolify interpolates
|
||
them). Coolify adds its own variables (`COOLIFY_FQDN`, `COOLIFY_URL`, `SOURCE_COMMIT`, `PORT`, `HOST`) — do not use
|
||
them instead of `NEXT_PUBLIC_SERVER_URL`. `.env.example` in the repo is the checklist of what to fill in.
|
||
|
||
### 4.3 Database migrations (Postgres)
|
||
|
||
Mongo needs no migrations — skip this section. Postgres: production never uses `push`; schema changes ship as
|
||
committed migrations (`pnpm payload migrate:create` locally).
|
||
|
||
**Not in Coolify's Pre-/Post-deployment commands:**
|
||
- *Pre-deployment* runs in the **old** (still running) container — old code, old migrations — and is **skipped on the
|
||
first deployment**;
|
||
- *Post-deployment* runs after Coolify has already switched traffic to the new container, and its failure is only logged.
|
||
|
||
**Run them when the new container starts, before it reports healthy** — one of:
|
||
|
||
```ts
|
||
// payload.config.ts — preferred: Payload runs pending migrations on init when NODE_ENV=production
|
||
import { migrations } from './migrations'
|
||
|
||
db: postgresAdapter({ pool: { connectionString: process.env.DATABASE_URI }, prodMigrations: migrations }),
|
||
```
|
||
|
||
```bash
|
||
# or the start command (needs the Payload CLI and sources in the image):
|
||
pnpm payload migrate && pnpm start
|
||
```
|
||
|
||
With the health check (§4.4) the new container gets traffic only after the migrations succeeded and the database
|
||
answers; a failed migration leaves the old container serving. Note: `prodMigrations` runs on every Payload init
|
||
with `NODE_ENV=production` — also during `next build` when the build reaches the database (§3a3).
|
||
|
||
**Backward-compatible migrations only.** During a rolling update the old container still serves on the migrated
|
||
schema: add columns/tables first, drop or rename in a later release (`ipal-migrate-fields` skill). Take a
|
||
**Backup now** (§4.6) before a large migration.
|
||
|
||
### 4.4 Health check and rolling updates
|
||
|
||
Coolify → the application → **Health Checks**: HTTP, path `/api/health`, port 3000, a start period long enough
|
||
for migrations. Coolify starts the new container while the old one keeps serving, waits until it is healthy, then
|
||
switches; an unhealthy new container is removed and **the old one stays**. Without a health check any started
|
||
container counts as ready. Rolling updates are off when the app publishes a host port, has a custom/fixed container
|
||
name, or a custom IP — avoid those.
|
||
|
||
The endpoint comes from the plugin — it does a real round-trip to the database (`find` with `limit: 1`, `depth: 0`)
|
||
and returns 200/503, so Coolify can tell "process alive" from "app ready, database reachable".
|
||
Usually a re-export from `lib/content` is enough (PROGRAMISTA.md §2.8) — `healthRoute` is
|
||
`createHealthRoute` pinging the pages collection from `createContentHelpers`:
|
||
|
||
```ts
|
||
// app/api/health/route.ts
|
||
export { healthRoute as GET } from '@/lib/content'
|
||
export const dynamic = 'force-dynamic' // never prerender/cache health
|
||
```
|
||
|
||
Custom settings — `createHealthRoute` directly:
|
||
|
||
```ts
|
||
import { createHealthRoute } from '@intecion/ipal-kit'
|
||
import { getCachedPayload } from '@/lib/content'
|
||
export const dynamic = 'force-dynamic'
|
||
export const GET = createHealthRoute({ getCachedPayload, collection: 'pages' })
|
||
```
|
||
|
||
| Option | Default | Description |
|
||
|---|---|---|
|
||
| `getCachedPayload` | — (required) | the same accessor as in the rest of the app |
|
||
| `collection` | `'pages'` | collection pinged by the round-trip — must exist |
|
||
| `extra` | — | `async () => ({ … })` — extra checks, the result is appended to the body (after the base fields — the same keys override them); an exception → 503 |
|
||
|
||
Response (`content-type: application/json`, `cache-control: no-store`):
|
||
- 200: `{ status: 'ok', db: 'up', timestamp, tookMs, …extra }`
|
||
- 503: `{ status: 'error', db: 'down', timestamp, tookMs }` — no error details (they go to the
|
||
server log: `[ipal] createHealthRoute: database unreachable`). An exception from `extra` also gives `db: 'down'`.
|
||
|
||
**Turn off / override:** the route is opt-in — without the file `app/api/health/route.ts` nothing is created;
|
||
you can also write your own route from scratch (or point the health check at the home page — no database check).
|
||
|
||
### 4.5 Rollback
|
||
|
||
Coolify → the application → **Rollback** → *Available images* → roll back to an earlier image. Only images kept by
|
||
the image retention setting (*Images to keep*) are available — keep a few. A rollback swaps the code only: it does
|
||
**not** undo database migrations, volumes or external services. If a migration has to be undone → restore the backup
|
||
taken before the deploy (§4.6), then roll back the image.
|
||
|
||
### 4.6 Database backups
|
||
|
||
- Coolify → **S3 Storages**: add the backup target (any S3-compatible, e.g. a Cloudflare R2 bucket for backups —
|
||
not the media bucket) and validate the connection.
|
||
- The database resource → **Backups**: a schedule (daily or cron), *Enable S3*, retention for local and S3 copies
|
||
(count / days / size); raise the timeout for large databases. Postgres backups are `pg_dump` custom-format files.
|
||
- **Backup now** before every risky operation: a seed that updates content, a large migration, a field migration.
|
||
- **Restore**: the database resource → **Import Backup** (upload a file, a server path, or a file from S3) → check the
|
||
generated restore command → start and watch the restore output. Stop writes from the app first. Manual
|
||
alternative: `pg_restore --clean --if-exists --no-owner -d "$DATABASE_URI" backup.dump`.
|
||
- **Test restores** periodically into a throw-away database — an untested backup is not a backup.
|
||
|
||
Mongo resources have the same Backups / Import Backup screens (`mongodump` archives).
|
||
|
||
### 4.7 Running a command in production (seed, one-off scripts)
|
||
|
||
Coolify → the application → **Terminal** → pick the app container (or on the server:
|
||
`docker exec -it <container> sh`). The container has the runtime env, so scripts reach the production database.
|
||
For a seed (script, flags and data format: [seeding.md](./seeding.md)):
|
||
|
||
1. **dry run** — `SEED_DRY_RUN=1 pnpm payload run scripts/seed-content.ts`, read the planned changes;
|
||
2. **Backup now** on the database (§4.6);
|
||
3. the real run; check the panel and the site.
|
||
|
||
The seed script and its dependencies must be in the image (they are when Coolify builds from the whole repo).
|
||
|
||
### 4.8 Media persistence
|
||
|
||
With R2 (recommended) media live outside the container and survive redeploys and rollbacks. Without R2 media are on
|
||
the container disk → add a Coolify **Persistent Storage** volume for the upload directory (the upload collection's
|
||
`staticDir` — by default a folder named after the slug, e.g. `media`; check the absolute path inside the container), otherwise every redeploy deletes them. See storage.md.
|
||
|
||
### Integrations in the panel
|
||
|
||
Mail (SMTP/Graph) and Turnstile errors are visible in the panel after deploy: an alert on the dashboard and a banner on
|
||
the Site Integrations tab — see [integrations.md](./integrations.md).
|
||
|
||
### Other hosts
|
||
|
||
Not used for our projects. The plugin is host-agnostic: on any Node host keep the same rules — `NEXT_PUBLIC_*`
|
||
at build time, secrets at runtime, migrations before the new version takes traffic, a health check on `/api/health`,
|
||
media in R2 or on a persistent disk.
|
||
|
||
---
|
||
|
||
## 5. AFTER DEPLOY — checks
|
||
|
||
- [ ] Home page `/` redirects to a locale (`/pl`)
|
||
- [ ] Panel `/admin` works, login OK
|
||
- [ ] The form sends (test from the panel: Send test)
|
||
- [ ] Media display — through the app: `curl -sI https://klient.pl/api/media/file/<file>` → 200; media domain: no 403
|
||
- [ ] Coolify: health check green, a scheduled backup exists (§4.4, §4.6)
|
||
- [ ] Favicon in `<head>` (see seo.md — Google caches it slowly)
|
||
- [ ] HTTPS + security headers (check e.g. securityheaders.com)
|
||
- [ ] Sitemap `/sitemap.xml` and `/robots.txt` respond
|
||
- [ ] DNS records from §6 added and checked with `dig`
|
||
|
||
---
|
||
|
||
## 6. DNS — records to add to the zone
|
||
|
||
Our team runs the projects' DNS zones (our servers or servers we
|
||
manage). **The plugin automates nothing in DNS** — a human adds the records below
|
||
in the client's domain zone. The agent prepares the list with the values and
|
||
checks with `dig` after propagation. Check on the zone's authoritative server
|
||
(`dig @<ns> …`) and on a public resolver (`@1.1.1.1`) to rule out caching.
|
||
|
||
| # | Purpose | Record | Value | Check |
|
||
|---|---|---|---|---|
|
||
| 1 | Site (apex domain) | `A` / `AAAA` for `klient.pl` | IP of the Coolify server running the app | `dig +short klient.pl A` → server IP |
|
||
| 2 | `www` | `CNAME www` → `klient.pl` (or `A` → the same IP) | — | `dig +short www.klient.pl` → same IP; `curl -sI https://www.klient.pl` → 301/308 to the host from `NEXT_PUBLIC_SERVER_URL` (Coolify redirect, §4.1) |
|
||
| 3 | TLS certificate — Let's Encrypt via Coolify's proxy | `CAA klient.pl` (only when the zone already has CAA records) | `0 issue "letsencrypt.org"`; port 80 on the server reachable from the internet (HTTP challenge) | `dig +short klient.pl CAA` — no CAA records = any CA may issue; `curl -sI https://klient.pl` → valid certificate |
|
||
| 4 | **Google Search Console** — domain verification | `TXT` on `klient.pl` (apex) | `google-site-verification=<code from GSC>` (property type **Domain**) | `dig +short TXT klient.pl \| grep google-site-verification` → then GSC → Verify |
|
||
| 5 | **Bing Webmaster** (if used) | simplest: **import from Search Console** in Bing (no DNS); otherwise `CNAME <code>` → `verify.bing.com` | code from Bing | `dig +short CNAME <code>.klient.pl` → `verify.bing.com.` |
|
||
| 6 | E-mail — sender domain **SPF** | `TXT` on the domain of the From address | `v=spf1 include:<provider> -all` (Microsoft 365: `include:spf.protection.outlook.com`) — **one** SPF record per domain, add the include to the existing one | `dig +short TXT <domain> \| grep v=spf1` → exactly one result |
|
||
| 7 | E-mail — **DKIM** | per provider: `CNAME selector1._domainkey` / `selector2._domainkey` (Microsoft 365) or `TXT <selector>._domainkey` with the key | values from the mail provider's panel | `dig +short CNAME selector1._domainkey.<domain>` (or `TXT`) → provider's value; then turn on DKIM at the provider |
|
||
| 8 | E-mail — **DMARC** | `TXT _dmarc.<domain>` | start: `v=DMARC1; p=none; rua=mailto:dmarc@<domain>`, after checking the reports → `p=quarantine` | `dig +short TXT _dmarc.<domain>` |
|
||
| 9 | Media in R2 | **default: none** — `R2_PUBLIC_URL` empty, media served by the app; with a media domain: the R2 Custom Domain in the Cloudflare account that hosts that zone (see below) | — | through the app: `curl -sI https://klient.pl/api/media/file/<file>` → 200; media domain: `curl -sI https://<media-domain>/<file>` → 200 (root `/` may return 404, storage.md) |
|
||
|
||
**Which domain gets SPF/DKIM/DMARC (rows 6–8)** — the one in the **From** address of sent mail:
|
||
- **SMTP from the panel** transport → the domain from the *From address* field in Site Integrations (usually the client's
|
||
domain); the records come from that mailbox's provider;
|
||
- **Graph** transport → From is always `GRAPH_SENDER` (agency mailbox, [email.md](./email.md)) —
|
||
SPF/DKIM/DMARC are set once for the agency domain, not per project; the address from the panel goes into Reply-To.
|
||
|
||
Without SPF+DKIM aligned with the From domain (DMARC alignment) form mail lands in spam
|
||
or is rejected — the *Send test* button in the panel will show "sent", and the mail still will not arrive.
|
||
Check the `Authentication-Results` header in the received test: `spf=pass`, `dkim=pass`, `dmarc=pass`.
|
||
|
||
**Cloudflare R2 (row 9):** an R2 bucket custom domain must belong to a zone **in the same Cloudflare
|
||
account** with full setup (nameservers at Cloudflare). A CNAME ("partial") setup for a zone kept on other DNS
|
||
servers needs a Business or Enterprise plan. Our zones are on our own servers, so `media.klient.pl` cannot simply
|
||
be attached. Options, in order of preference:
|
||
|
||
1. **Serve media through the app (default)** — leave `R2_PUBLIC_URL` empty. Files are stored in R2, Payload serves
|
||
them at `/api/media/file/<name>` on the site's own domain: no DNS record, works on any zone. Cost: media traffic
|
||
passes through the app (next/image caches optimized variants); `ipalEnvRules({ storage: true })` accepts an
|
||
empty `R2_PUBLIC_URL` (env.md). Details: storage.md.
|
||
2. **A dedicated media domain on Cloudflare** — a separate domain whose zone is in our Cloudflare account (e.g.
|
||
`klient-media.com`), attached as the bucket's Custom Domain → `R2_PUBLIC_URL=https://<that domain>`. CDN and
|
||
cache rules included; for media-heavy sites.
|
||
3. A reverse proxy/cache on the Coolify server (`media.klient.pl` → the bucket) — possible, more moving parts.
|
||
4. `*.r2.dev` — rate-limited, **dev/testing only**, never production.
|
||
|
||
**Cookie crawler (once per team, not per site):** `cookie-crawler.<team domain>` → `A`/`AAAA` to the Coolify server running the scanner service ([cookie-scanner.md](./cookie-scanner.md#scanner-service-on-coolify)). A site using `cookieScanner.crawl` needs no record of its own.
|
||
|
||
**No DNS records needed:** Turnstile (hostname list set in the Cloudflare panel on the widget, not in
|
||
DNS), IndexNow (key file served by the app), llms.txt, MCP, Markdown, sitemap.
|
||
|
||
**Search Console through DNS, not a meta tag.** We verify with a TXT record (row 4) — it covers
|
||
all protocols and subdomains. The meta tag verification fields in Site Settings (if the plugin
|
||
version has them) are **optional and normally empty**. We do not use the Search Console API — submit the
|
||
sitemap `https://klient.pl/sitemap.xml` once by hand in GSC (and in Bing).
|
||
|
||
---
|
||
|
||
## WHY THIS MATTERS
|
||
|
||
- **One env list** — nobody guesses what is missing
|
||
- **Repeatable deploy** — frozen-lockfile, the same order, every project the same way
|
||
- **Secrets safe** — env/runtime, never the repo
|
||
- **Media survive** — R2 or a volume, they do not disappear on redeploy
|