Relax contact route matching
This commit is contained in:
parent
cbbd6debbd
commit
72a1dc6541
1 changed files with 18 additions and 15 deletions
|
|
@ -163,10 +163,24 @@ const handleContact = async (request: Request, env: Env) => {
|
|||
export default {
|
||||
async fetch(request: Request, env: Env): Promise<Response> {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue