Module 12 · ship · advanced
Solutions 12 · Self-hosting and Client Delivery
Exercise 1
Replace Anything Down? → Send Alert with a Code node Detect Changes (Run Once for All Items) after Summary on the scheduled path:
const state = $getWorkflowStaticData('global');
const prev = state.down ?? [];
const now = $input.first().json.down;
const newlyDown = now.filter(u => !prev.includes(u));
const recovered = prev.filter(u => !now.includes(u));
state.down = now;
const lines = [
...newlyDown.map(u => `🔴 DOWN: ${u}`),
...recovered.map(u => `🟢 RECOVERED: ${u}`),
];
return lines.length ? [{ json: { text: lines.join('\n') } }] : [];
→ Telegram/Slack/Gmail with {{ $json.text }}. Returning [] means no alert. Static data is only saved for production (published) executions, not manual test runs.
Exercise 2
On your machine, in an empty folder with the deploy files and the same .env:
tar -xzf 20261015-023000.tar.gz
docker compose -p restore-test -f docker-compose.prod.yml up -d postgres
gunzip -c 20261015-023000/postgres.sql.gz | docker compose -p restore-test -f docker-compose.prod.yml exec -T postgres psql -U n8n n8n
docker compose -p restore-test -f docker-compose.prod.yml up -d
(Use DOMAIN=localhost locally; Caddy serves a local certificate.) Log in with the original owner account; workflows, credentials and execution history are all in the dump. The workflow and credential JSON files are a second, more portable copy: n8n import:workflow --separate --input=<dir> and n8n import:credentials --separate --input=<dir> load them into any instance with the same encryption key.
Clean up: docker compose -p restore-test -f docker-compose.prod.yml down -v.
Exercise 3
- Webhook
Health API→ Authentication: Header Auth → new credential: NameX-Monitor-Token, Value: a long random string (openssl rand -hex 24). - Publish.
curl -i https://n8n.yourdomain.com/webhook/ops/health # 403
curl -i -H "X-Monitor-Token: <secret>" https://n8n.yourdomain.com/webhook/ops/health # 200/503
Configure the same header in your external uptime monitor. Apply this to every webhook that triggers side effects (Modules 03, 07, 10).