Blog · Infrastructure
A maintenance page at the edge: one Worker in front of 13 domains

The websites N3XUS operates run on our own servers in São Paulo and reach the internet through Cloudflare, over a tunnel. When a server shut down, the tunnel dropped or the lab’s internet went out, visitors got Cloudflare’s default error screen: “Error 522” or “Error 1033”, which makes a site look abandoned.
We solved this with a Worker that sits in front of all 13 domains in the account. It runs on Cloudflare itself, so it keeps responding even with the whole lab turned off.
In short
- The Worker passes every request through untouched. Only when the origin does not respond does it return a N3XUS page in place of the error.
- The response is a 503 with
Retry-After, a server error, and not a 200 page that a search engine could index as content. - APIs, webhooks and apps get short JSON, never HTML. The application’s own legitimate 503 passes straight through.
- We tested it live with a subdomain pointed at
100::, an address that never responds, and the Worker returned the page with the real 522 code.
When to replace the error (and when not to)
The main rule lives in a list of status codes. These are the ones that mean “the origin did not respond”:
// 502/504 do proxy, 520 a 527 da Cloudflare, 530 (túnel sem conector, erro 1033)
const ORIGEM_FORA = new Set([502, 504, 520, 521, 522, 523, 524, 525, 526, 527, 530]);
503 was left out on purpose. Many applications use that code to say “I am under maintenance” or “rate limit reached”. If the Worker replaced that 503, it would hide a correct response from the application.
There is a second case: the server is up, but the project is stopped in Coolify. Then Traefik responds, with a short text (404 page not found or no available server). The Worker only replaces that response when it is exactly that text, in text/plain, at most 64 bytes, and only for clients asking for an HTML page. A Go API returns the same text on its default 404, and its client needs to keep receiving the original 404.
The maintenance response
What the Worker returns depends on who asked:
| Who asked | Response |
|---|---|
Browser (GET or HEAD with accept: text/html) |
503, HTML page, Retry-After: 60, cache-control: no-store |
| API, webhook, app (any other case) | 503, {"erro":"servidor_em_manutencao","codigo":522,"tente_em_segundos":60} |
The page shows the domain, the error code, the time and the Cloudflare Ray ID, so the case can be found in the logs later. It also checks on its own whether the site is back: it sends a HEAD to its own URL after 15, 30 and 30 seconds, and then every 60 seconds. The maintenance page goes out with the x-n3xus-manutencao header; when a response arrives without it, the page reloads.
The page has its own CSP with a fresh nonce on every response, since the CSS and the script live in the HTML itself.
For Google, 5xx errors make the crawler slow down its crawl rate, and URLs that are already indexed stay in the index for a while; only a persistent error removes them. Retry-After tells the client when to try again.
The case of the N3XUS website
Our own website has a better fallback than the maintenance page. The same build is also published to Cloudflare Pages, as a mirror. When the origin goes down, the Worker fetches the page from the mirror and serves it on n3xus.dev itself:
- it removes the
x-robots-tag: noindexthat Pages adds to*.pages.devaddresses; - it rewrites redirects from the mirror to the main domain;
- it leaves
/admin/and the internal camera pages on the maintenance page, because they do not exist on the mirror.
If the mirror also fails, it falls back to the maintenance page.
How we tested it
First, locally: we ran the published worker.js with a mocked fetch and 19 scenarios. Among them: origin down, tunnel without a connector, connection failure, Coolify stopped, a 503 from the application, a normal 404, the mirror, the mirror down, HEAD, POST and an attempt to inject HTML through the URL. All of them passed, and the page rendered in Chromium had no CSP violations.
Then, live. We created manutencao-teste.n3xus.dev with an AAAA 100:: record in proxied mode and a Worker route on that name only. The 100::/64 prefix is reserved for discard (RFC 6666): Cloudflare tries, cannot reach the origin and generates a real 522.
curl -s -o /dev/null -w "%{http_code} %{content_type}\n" \
-H 'accept: application/json' https://manutencao-teste.n3xus.dev/api/x
# 503 application/json; charset=utf-8
In the browser, the page showed “Code 522” and the real Ray ID. After the test, we deleted the record and the route.
What we learned
- Replacing an error has a diagnostic cost. That is why the page shows the original code and the Ray ID, and only replaces what is an origin failure. The application’s response is never hidden.
- Separate browsers from machines. HTML sent to a webhook becomes a parse error on the other side; short JSON becomes an error the client knows how to handle.
- A token to publish, with the minimum. We publish through the API with an account token that can only edit Worker scripts, restricted to the lab’s IP and valid for 7 days. One detail: the dashboard shows the token’s ID (32 hexadecimal characters); the secret appears only once, at creation. And an account token (
cfat_) is verified at/accounts/{id}/tokens/verify:/user/tokens/verifyanswers “Invalid API Token” even when the token is valid. - Every request goes through the Worker. Every hit to the 13 domains counts as an invocation on the Workers plan. It is worth checking your plan’s limit before putting a Worker on a wildcard route.
References
- Cloudflare: 5xx errors
- Cloudflare Workers: routes and pricing and limits
- Cloudflare: account-owned tokens
- Google Search Central: HTTP and network errors
- MDN: Retry-After
- RFC 6666: IPv6 discard prefix
Want a maintenance page like this in front of your websites? Talk to us.

