Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions netlify/functions/qa-block.ts
Original file line number Diff line number Diff line change
@@ -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<Response> => {
if (process.env.QA_FORCE_403 === "true") {
const blockedHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>QA Block Test</title>
</head>
<body>
<h1>403 Forbidden</h1>
</body>
</html>
`;
return new Response(blockedHtml, {
status: 403,
headers: { "Content-Type": "text/html; charset=utf-8" },
});
}

const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>QA Block Test</title>
</head>
<body>
<h1>QA Block Test</h1>
</body>
</html>
`;

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