-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (30 loc) · 901 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require("express");
const app = express();
const fetch = require("node-fetch");
app.use(express.static('public'));
app.use(require('express-minify-html-terser')({
override: true,
exception_url: false,
htmlMinifier: {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: false,
removeEmptyAttributes: false,
minifyJS: true
}
}));
app.all("/", async (req, res) => {
res.render("search.ejs")
});
app.all("/:word", async (req, res) => {
const data = await fetch("https://api.dictionaryapi.dev/api/v2/entries/en_US/" + encodeURIComponent(req.params.word));
if (!data.ok) return res.render("error.ejs");
res.render("word.ejs", {
data: (await data.json())[0]
})
});
const listener = app.listen(8000, () => {
console.log("Your app is listening on port " + listener.address().port);
});
"";