From 72a1dc6541003b002283974a34d7790ca2bd16f9 Mon Sep 17 00:00:00 2001 From: Calum Muir Date: Mon, 22 Dec 2025 13:58:24 +0000 Subject: [PATCH] Relax contact route matching --- src/worker.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/worker.ts b/src/worker.ts index f850726..0282a1c 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -163,10 +163,24 @@ const handleContact = async (request: Request, env: Env) => { export default { async fetch(request: Request, env: Env): Promise { const url = new URL(request.url); - if ( - url.pathname === "/api/contact" || - url.pathname === "/api/contact/" - ) { + const contactPath = url.pathname; + const isContact = + contactPath === "/api/contact" || + contactPath === "/api/contact/" || + contactPath.endsWith("/api/contact") || + contactPath.endsWith("/api/contact/"); + if (isContact) { + if (request.method === "GET" && url.searchParams.has("debug")) { + return jsonResponse({ + ok: true, + hasTurnstileSecret: Boolean(env.TURNSTILE_SECRET_KEY), + hasAzureConnectionString: Boolean( + env.AZURE_COMMUNICATION_CONNECTION_STRING, + ), + hasContactFromEmail: Boolean(env.CONTACT_FROM_EMAIL), + hasContactToEmail: Boolean(env.CONTACT_TO_EMAIL), + }); + } if (request.method !== "POST") { return jsonResponse( { ok: false, error: "Method not allowed." }, @@ -175,17 +189,6 @@ export default { } return handleContact(request, env); } - if (url.pathname === "/api/contact-debug") { - return jsonResponse({ - ok: true, - hasTurnstileSecret: Boolean(env.TURNSTILE_SECRET_KEY), - hasAzureConnectionString: Boolean( - env.AZURE_COMMUNICATION_CONNECTION_STRING, - ), - hasContactFromEmail: Boolean(env.CONTACT_FROM_EMAIL), - hasContactToEmail: Boolean(env.CONTACT_TO_EMAIL), - }); - } if (env.ASSETS?.fetch) { return env.ASSETS.fetch(request); }