From 6937e7c993ebf06b7914f794294ff542f1078275 Mon Sep 17 00:00:00 2001 From: rift <117926989+Riftriot@users.noreply.github.com> Date: Fri, 29 Dec 2023 11:20:07 -0600 Subject: [PATCH] Autofill backend --- server.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server.ts b/server.ts index a2c413e..4dd1785 100644 --- a/server.ts +++ b/server.ts @@ -77,6 +77,16 @@ app.register(fastifyStatic, { wildcard: false }); +app.get("/search=:query", async (req, res) => { + const { query } = req.params as { query: string }; // Define the type for req.params + + const response = await fetch( + `http://api.duckduckgo.com/ac?q=${query}&format=json` + ).then((apiRes) => apiRes.json()); + + res.send(response); +}); + app.setNotFoundHandler((req, res) => { res.sendFile("index.html"); // SPA catch-all });