From fc7a0e6b70f4a060d741aaa948ee24e43fe9c10c Mon Sep 17 00:00:00 2001 From: belminpre Date: Tue, 9 Jun 2026 10:31:14 +0200 Subject: [PATCH] Add /qa-status Netlify function for Prerender 5xx cache-refresh testing A QA-only endpoint that returns either 200 + minimal HTML or a real HTTP 500 + minimal HTML, controlled at request time by the Netlify env var QA_FORCE_500. Used to exercise Prerender's error -> recovery flow by toggling the var and redeploying across deploys. - netlify/functions/qa-status.ts: new function, both branches return Content-Type: text/html; charset=utf-8 so only the status code varies. - netlify.toml: declare [functions] directory explicitly and add a /qa-status -> /.netlify/functions/qa-status rewrite (status = 200, preserves upstream status). The rewrite is placed ABOVE the SPA catch-all so it isn't swallowed by /* -> /index.html. No app routes, pages, or dependencies changed. Co-authored-by: Cursor --- netlify.toml | 15 ++++++++++++ netlify/functions/qa-status.ts | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 netlify/functions/qa-status.ts diff --git a/netlify.toml b/netlify.toml index 7723621..7e9e539 100644 --- a/netlify.toml +++ b/netlify.toml @@ -5,6 +5,21 @@ publish = "dist" command = "npm run build" +# Netlify Functions live in netlify/functions/ (this is Netlify's default, +# stated explicitly for clarity). +[functions] + directory = "netlify/functions" + +# QA-only: expose the qa-status function at the clean path /qa-status so +# Prerender sees a normal-looking page URL. Must be declared BEFORE the +# SPA catch-all below, otherwise /* swallows it. status = 200 is a Netlify +# rewrite (proxy), which preserves the upstream function's actual status +# code (200 or 500) — it does NOT force a 200 response. +[[redirects]] + from = "/qa-status" + to = "/.netlify/functions/qa-status" + status = 200 + # Redirect all requests to /index.html for SPA routing [[redirects]] from = "/*" diff --git a/netlify/functions/qa-status.ts b/netlify/functions/qa-status.ts new file mode 100644 index 0000000..5f4801a --- /dev/null +++ b/netlify/functions/qa-status.ts @@ -0,0 +1,45 @@ +// QA-only Netlify Function used to test Prerender's error -> recovery (cache +// refresh) flow. Toggle the HTTP status across deploys via the Netlify env +// var QA_FORCE_500: +// QA_FORCE_500="true" -> HTTP 500, plain text body +// anything else/unset -> HTTP 200, minimal HTML page +// Reached publicly via /qa-status (see redirect in netlify.toml). + +export default async (_req: Request): Promise => { + if (process.env.QA_FORCE_500 === "true") { + const errorHtml = ` + + + + + 500 - QA + + +

Server Error

+ + +`; + return new Response(errorHtml, { + status: 500, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); + } + + const html = ` + + + + + QA Status Test + + +

QA Status Test

+ + +`; + + return new Response(html, { + status: 200, + headers: { "Content-Type": "text/html; charset=utf-8" }, + }); +};