From 4a50e5df3952688787c21b8874a23a89acb92906 Mon Sep 17 00:00:00 2001 From: Korbs Date: Fri, 25 Oct 2024 14:53:06 -0400 Subject: [PATCH] Use endpoint request over script workaround --- source/src/pages/api/search/web.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 source/src/pages/api/search/web.ts diff --git a/source/src/pages/api/search/web.ts b/source/src/pages/api/search/web.ts new file mode 100644 index 0000000..0782919 --- /dev/null +++ b/source/src/pages/api/search/web.ts @@ -0,0 +1,15 @@ +import type { APIRoute } from "astro" + +export const POST: APIRoute = async ({ request, redirect }) => { + // Get Form Data + const formData = await request.formData() + const web_search = formData.get("websearch")?.toString() + + // If the user presses "Enter" on a blank search, return to home + if (!web_search) { + return redirect("/") + } + + // Go to search term + return redirect("/web?=" + web_search) +} \ No newline at end of file