From 86a04f42be6f4e467c0434b444389a3f80348569 Mon Sep 17 00:00:00 2001 From: Ashley Date: Wed, 8 Jun 2022 17:11:29 +0300 Subject: [PATCH] new search! --- server.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 3d16c5d1..522aab32 100644 --- a/server.js +++ b/server.js @@ -98,8 +98,24 @@ app.get("/api/search", async (req, res) => { if (!query) { return res.redirect("/"); } - fetcher.searcher(query,res) -}); + return res.redirect(`/search?query=${query}`); + + }); +app.get("/search", async (req, res) => { + const { toJson } = require("xml2json"); + const query = req.query.query; + const search = await fetch( + `https://lighttube.herokuapp.com/api/search?query=${query}` + ); + const text = await search.text(); + const j = JSON.parse(toJson(text)); + if (!query) { + return res.redirect("/"); + } + renderTemplate(res, req, "search.ejs", { + j: j, + }); + }); app.get("/css/:id", (req, res) => { res.sendFile(__dirname + `/css/${req.params.id}`); });