From c25ee03a992b69ba0f6712b6ad0b8766d889b2be Mon Sep 17 00:00:00 2001 From: belminpre Date: Fri, 12 Jun 2026 00:45:34 +0200 Subject: [PATCH] Add /qa-block Netlify function for Prerender 403<->200 toggle testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the qa-status.ts pattern but toggles between 403 Forbidden and 200 OK (instead of 500/200) via the build-time env var QA_FORCE_403: QA_FORCE_403="true" -> HTTP 403 + text/html minimal body (QA Block Test,

403 Forbidden

) anything else/unset -> HTTP 200 + text/html minimal body (QA Block Test,

QA Block Test

) Same handler signature, env-read pattern, and Response shape as qa-status.ts. Kept as its own function (not folded into qa-code.ts) because the env-driven toggle does not fit the generic fixed-status dispatcher — same reasoning as qa-status.ts. QA_FORCE_403 is captured at deploy time (process.env), so flipping it in the Netlify UI requires a redeploy (push to main, or Netlify UI -> Deploys -> Trigger deploy). - netlify/functions/qa-block.ts: new function. - netlify.toml: add /qa-block -> /.netlify/functions/qa-block rewrite with status = 200 (rewrite TYPE, preserves upstream 200/403 + Content-Type). Placed immediately after the existing /qa-status block (grouping the two env-toggled endpoints) and before the SPA /* catch-all. qa-status.ts, qa-code.ts, and all other rewrites are untouched. No app routes, pages, or dependencies changed. Co-authored-by: Cursor --- netlify.toml | 12 +++++++++ netlify/functions/qa-block.ts | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 netlify/functions/qa-block.ts diff --git a/netlify.toml b/netlify.toml index f2705b6..12f9162 100644 --- a/netlify.toml +++ b/netlify.toml @@ -20,6 +20,18 @@ to = "/.netlify/functions/qa-status" status = 200 +# QA-only: expose the qa-block function at the clean path /qa-block. +# Same env-toggled pattern as /qa-status above (its own dedicated +# function rather than the parameterized qa-code, because the build- +# time QA_FORCE_403 env var does not fit the generic dispatcher). +# Same status = 200 rewrite-proxy mechanism — preserves the function's +# real upstream status (200 or 403) and Content-Type. Must remain +# BEFORE the SPA catch-all below. +[[redirects]] + from = "/qa-block" + to = "/.netlify/functions/qa-block" + status = 200 + # QA-only: route /qa-301 to the parameterized qa-code function, which # emits a real HTTP 301 + Location header for this path. Same # rewrite-proxy mechanism as /qa-status above — status = 200 is the diff --git a/netlify/functions/qa-block.ts b/netlify/functions/qa-block.ts new file mode 100644 index 0000000..a679031 --- /dev/null +++ b/netlify/functions/qa-block.ts @@ -0,0 +1,47 @@ +// QA-only Netlify Function used to test Prerender's handling of 4xx +// (blocked) pages on a clean, page-looking URL. Toggle the HTTP status +// across deploys via the Netlify env var QA_FORCE_403: +// QA_FORCE_403="true" -> HTTP 403, minimal HTML body +// anything else/unset -> HTTP 200, minimal HTML body +// Reached publicly via /qa-block (see redirect in netlify.toml). +// +// Kept as its own function (not folded into qa-code.ts) because the +// build-time env toggle does not fit the generic fixed-status +// dispatcher — same reasoning as qa-status.ts. + +export default async (_req: Request): Promise => { + if (process.env.QA_FORCE_403 === "true") { + const blockedHtml = ` + + + + QA Block Test + + +

403 Forbidden

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

QA Block Test

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