diff --git a/functions/api/contact.ts b/functions/api/contact.ts index 90dc897..243cfc6 100644 --- a/functions/api/contact.ts +++ b/functions/api/contact.ts @@ -31,7 +31,7 @@ const parseConnectionString = (connectionString: string) => { }; }; -export const onRequestPost: PagesFunction = async ({ request, env }) => { +const handlePost: PagesFunction = async ({ request, env }) => { const formData = await request.formData(); const name = readFormField(formData.get("name")); const email = readFormField(formData.get("email")); @@ -147,3 +147,13 @@ export const onRequestPost: PagesFunction = async ({ request, env }) => { return jsonResponse({ ok: true }); }; + +export const onRequest: PagesFunction = async (context) => { + if (context.request.method !== "POST") { + return jsonResponse( + { ok: false, error: "Method not allowed." }, + 405, + ); + } + return handlePost(context); +};