From 292775c7fbc986a60a30076b395eca5e5beeecdb Mon Sep 17 00:00:00 2001 From: belminpre Date: Tue, 9 Jun 2026 21:36:31 +0200 Subject: [PATCH] Add /qa-301 Netlify function for Prerender 3xx testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A second QA-only endpoint alongside /qa-status. Always returns a real HTTP 301 with Location: https://weirdanimals.life/, set by the function itself. Used to test Prerender's handling of 3xx responses on a clean, page-looking URL. - netlify/functions/qa-301.ts: new function returning 301 + Location. - netlify.toml: add /qa-301 -> /.netlify/functions/qa-301 rewrite. The status = 200 here is the rewrite TYPE (proxy), not a forced response code — Netlify preserves the function's 301 status AND its Location header through the rewrite. Placed between the existing /qa-status rewrite and the SPA /* catch-all so it is not swallowed. The existing /qa-status rewrite and function are untouched. No app routes, pages, or dependencies changed. Co-authored-by: Cursor --- netlify.toml | 10 ++++++++++ netlify/functions/qa-301.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 netlify/functions/qa-301.ts diff --git a/netlify.toml b/netlify.toml index 7e9e539..321f223 100644 --- a/netlify.toml +++ b/netlify.toml @@ -20,6 +20,16 @@ to = "/.netlify/functions/qa-status" status = 200 +# QA-only: expose the qa-301 function at the clean path /qa-301. Same +# rewrite-proxy mechanism as /qa-status above (status = 200 is the +# rewrite TYPE, not a forced response code) — it preserves the +# function's actual 301 status code AND its Location header. Must +# remain BEFORE the SPA catch-all below. +[[redirects]] + from = "/qa-301" + to = "/.netlify/functions/qa-301" + status = 200 + # Redirect all requests to /index.html for SPA routing [[redirects]] from = "/*" diff --git a/netlify/functions/qa-301.ts b/netlify/functions/qa-301.ts new file mode 100644 index 0000000..dc85a9b --- /dev/null +++ b/netlify/functions/qa-301.ts @@ -0,0 +1,17 @@ +// QA-only Netlify Function that always returns a real HTTP 301 redirect +// to the site homepage. Used to test Prerender's handling of 3xx +// responses on a clean, page-looking URL. Reached publicly via /qa-301 +// (see redirect in netlify.toml). +// +// The 301 status code and Location header are set by THIS function and +// passed through unchanged by Netlify's status=200 rewrite proxy — the +// client sees the 301 + Location, Netlify does not auto-follow it. + +export default async (_req: Request): Promise => { + return new Response(null, { + status: 301, + headers: { + Location: "https://weirdanimals.life/", + }, + }); +};