diff --git a/functions/index.js b/functions/index.js index f09754b..bc24096 100644 --- a/functions/index.js +++ b/functions/index.js @@ -9,6 +9,10 @@ import {trackQuery} from '../lib/mongo.js'; export const onRequestGet = async (context) => { const startTime = Date.now(); + const { request, env } = context; + const { searchParams } = new URL(request.url); + const { q} = Object.fromEntries(searchParams.entries()); + const { q: searchQuery, lang } = parseQuery(q); // Save used queries for analytics if (q) { trackQuery(context.env, { q, hasResults }) @@ -17,11 +21,6 @@ export const onRequestGet = async (context) => { }); } - const { request, env } = context; - const { searchParams } = new URL(request.url); - const { q} = Object.fromEntries(searchParams.entries()); - const { q: searchQuery, lang } = parseQuery(q); - const searchTimeStamp = Date.now(); const result = q ? await search(env, searchQuery, lang) : null; const doneIn = Date.now() - searchTimeStamp;