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" }, + }); +};