From 4bfdf54d1a941ceb4a7ee7ed1d32a3b75c96ea58 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 11 Apr 2025 12:56:03 -0400 Subject: [PATCH] Allow types.ruff.rs for red-knot playground (#17358) --- playground/api/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/playground/api/src/index.ts b/playground/api/src/index.ts index 8410661a66..d75c8135f2 100644 --- a/playground/api/src/index.ts +++ b/playground/api/src/index.ts @@ -31,6 +31,8 @@ const PRODUCTION_HEADERS = { "Access-Control-Allow-Origin": "https://play.ruff.rs", }; +const ALLOWED_DOMAINS = ["https://playknot.ruff.rs", "https://types.ruff.rs"]; + export default { async fetch( request: Request, @@ -40,8 +42,12 @@ export default { const { DEV, PLAYGROUND } = env; const headers = DEV ? DEVELOPMENT_HEADERS : PRODUCTION_HEADERS; - if (!DEV && request.headers.get("origin") === "https://playknot.ruff.rs") { - headers["Access-Control-Allow-Origin"] = "https://playknot.ruff.rs"; + + if (!DEV) { + const origin = request.headers.get("origin"); + if (origin && ALLOWED_DOMAINS.includes(origin)) { + headers["Access-Control-Allow-Origin"] = origin; + } } switch (request.method) {