Relax contact route matching
This commit is contained in:
parent
cbbd6debbd
commit
72a1dc6541
1 changed files with 18 additions and 15 deletions
|
|
@ -163,19 +163,14 @@ const handleContact = async (request: Request, env: Env) => {
|
||||||
export default {
|
export default {
|
||||||
async fetch(request: Request, env: Env): Promise<Response> {
|
async fetch(request: Request, env: Env): Promise<Response> {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
if (
|
const contactPath = url.pathname;
|
||||||
url.pathname === "/api/contact" ||
|
const isContact =
|
||||||
url.pathname === "/api/contact/"
|
contactPath === "/api/contact" ||
|
||||||
) {
|
contactPath === "/api/contact/" ||
|
||||||
if (request.method !== "POST") {
|
contactPath.endsWith("/api/contact") ||
|
||||||
return jsonResponse(
|
contactPath.endsWith("/api/contact/");
|
||||||
{ ok: false, error: "Method not allowed." },
|
if (isContact) {
|
||||||
405,
|
if (request.method === "GET" && url.searchParams.has("debug")) {
|
||||||
);
|
|
||||||
}
|
|
||||||
return handleContact(request, env);
|
|
||||||
}
|
|
||||||
if (url.pathname === "/api/contact-debug") {
|
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
ok: true,
|
ok: true,
|
||||||
hasTurnstileSecret: Boolean(env.TURNSTILE_SECRET_KEY),
|
hasTurnstileSecret: Boolean(env.TURNSTILE_SECRET_KEY),
|
||||||
|
|
@ -186,6 +181,14 @@ export default {
|
||||||
hasContactToEmail: Boolean(env.CONTACT_TO_EMAIL),
|
hasContactToEmail: Boolean(env.CONTACT_TO_EMAIL),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (request.method !== "POST") {
|
||||||
|
return jsonResponse(
|
||||||
|
{ ok: false, error: "Method not allowed." },
|
||||||
|
405,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return handleContact(request, env);
|
||||||
|
}
|
||||||
if (env.ASSETS?.fetch) {
|
if (env.ASSETS?.fetch) {
|
||||||
return env.ASSETS.fetch(request);
|
return env.ASSETS.fetch(request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue