From 362ca9f7bb793b4996317b9b13524d64f24e41b9 Mon Sep 17 00:00:00 2001 From: Amelia <9247739-limesey@users.noreply.gitlab.com> Date: Sat, 4 Jun 2022 17:35:49 +0100 Subject: [PATCH] Rewrite portion of app.ts to work with scraper.ts changes --- src/server/app.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/server/app.ts b/src/server/app.ts index be09eed..af46372 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -1,6 +1,6 @@ import express from "express"; -import scraper from "../scaper"; +import * as scraper from "../scraper"; const app = express(); const PORT = 8080; @@ -10,12 +10,8 @@ app.listen(PORT, () => { }); app.get("/", async (req, res) => { - // res.send(`Defintion for '${req.query.term}!'`); - const term = req.query.term; - console.log(term); - if (term == undefined) { res .status(400) @@ -27,13 +23,11 @@ app.get("/", async (req, res) => { } try { - const data = await scraper( - `https://www.urbandictionary.com/define.php?term=${term}` - ); + const defintions = await scraper.getDefinitions(term.toString()); - res.send(data); + res.json(defintions); } catch (e) { - res.status(500); + res.sendStatus(500); console.error(e); } });