From 5cf431ec597da4667546e0095095fd5838dcadc6 Mon Sep 17 00:00:00 2001 From: belminpre Date: Thu, 11 Jun 2026 09:24:34 +0200 Subject: [PATCH] Add /qa-403 Netlify function for Prerender 4xx testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A third QA-only endpoint alongside /qa-status and /qa-301. Always returns a real HTTP 403 with Content-Type: text/html; charset=utf-8 and a minimal HTML body (403 - QA,

Forbidden

). Used to test Prerender's handling of 4xx responses on a clean, page-looking URL. - netlify/functions/qa-403.ts: new function returning 403 + HTML body. - netlify.toml: add /qa-403 -> /.netlify/functions/qa-403 rewrite. The status = 200 here is the rewrite TYPE (proxy), not a forced response code — Netlify preserves the function's 403 status and Content-Type through the rewrite. Placed between the existing /qa-301 rewrite and the SPA /* catch-all so it is not swallowed. The existing /qa-status and /qa-301 rewrites and functions are untouched. No app routes, pages, or dependencies changed. Co-authored-by: Cursor --- netlify.toml | 10 ++++++++++ netlify/functions/qa-403.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 netlify/functions/qa-403.ts diff --git a/netlify.toml b/netlify.toml index 321f223..29bc444 100644 --- a/netlify.toml +++ b/netlify.toml @@ -30,6 +30,16 @@ to = "/.netlify/functions/qa-301" status = 200 +# QA-only: expose the qa-403 function at the clean path /qa-403. Same +# rewrite-proxy mechanism as the QA endpoints above (status = 200 is +# the rewrite TYPE, not a forced response code) — it preserves the +# function's actual 403 status and its text/html Content-Type. Must +# remain BEFORE the SPA catch-all below. +[[redirects]] + from = "/qa-403" + to = "/.netlify/functions/qa-403" + status = 200 + # Redirect all requests to /index.html for SPA routing [[redirects]] from = "/*" diff --git a/netlify/functions/qa-403.ts b/netlify/functions/qa-403.ts new file mode 100644 index 0000000..3ccfa41 --- /dev/null +++ b/netlify/functions/qa-403.ts @@ -0,0 +1,28 @@ +// QA-only Netlify Function that always returns a real HTTP 403 +// Forbidden with a minimal HTML body. Used to test Prerender's +// handling of 4xx responses on a clean, page-looking URL. Reached +// publicly via /qa-403 (see redirect in netlify.toml). +// +// The 403 status code and Content-Type are set by THIS function and +// passed through unchanged by Netlify's status=200 rewrite proxy — +// the client sees a real 403, not a 200 carrying error text. + +export default async (_req: Request): Promise => { + const html = ` + + + + + 403 - QA + + +

Forbidden

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