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