Rewrite portion of app.ts to work with scraper.ts changes

This commit is contained in:
Amelia 2022-06-04 17:35:49 +01:00
parent 6dada66079
commit 362ca9f7bb
1 changed files with 4 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import express from "express"; import express from "express";
import scraper from "../scaper"; import * as scraper from "../scraper";
const app = express(); const app = express();
const PORT = 8080; const PORT = 8080;
@ -10,12 +10,8 @@ app.listen(PORT, () => {
}); });
app.get("/", async (req, res) => { app.get("/", async (req, res) => {
// res.send(`Defintion for '${req.query.term}!'`);
const term = req.query.term; const term = req.query.term;
console.log(term);
if (term == undefined) { if (term == undefined) {
res res
.status(400) .status(400)
@ -27,13 +23,11 @@ app.get("/", async (req, res) => {
} }
try { try {
const data = await scraper( const defintions = await scraper.getDefinitions(term.toString());
`https://www.urbandictionary.com/define.php?term=${term}`
);
res.send(data); res.json(defintions);
} catch (e) { } catch (e) {
res.status(500); res.sendStatus(500);
console.error(e); console.error(e);
} }
}); });