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 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);
}
});