Skip to content

Commit 7d29d03

Browse files
committed
Replace undici with native fetch; add prettier
1 parent 1b5f4bd commit 7d29d03

File tree

3 files changed

+370
-25
lines changed

3 files changed

+370
-25
lines changed

index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const express = require("express");
22
const { mf2 } = require("microformats-parser");
3-
const undici = require("undici");
43
const pkg = require("./package.json");
54
const app = express();
65
const port = process.env.PORT || 9000;
@@ -36,15 +35,15 @@ app.use(express.static("public"));
3635
app.get("/", async (req, res) => {
3736
if (req.query.url) {
3837
const url = req.query.url;
39-
const { body } = await undici.request(url, {
40-
maxRedirections: 2,
38+
await fetch(url, {
4139
headers: {
4240
accept: "text/html, text/mf2+html",
4341
},
4442
method: "GET",
43+
}).then(async (response) => {
44+
const html = await response.text();
45+
htmlToMf2(url, html, res);
4546
});
46-
const text = await body.text();
47-
htmlToMf2(url, text, res);
4847
} else {
4948
res.render("index.html.ejs", {
5049
version: `${pkg.version} (lib: ${mf2version})`,

package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
"yarn": "1.x"
99
},
1010
"scripts": {
11-
"start": "node index.js"
11+
"start": "node index.js",
12+
"prepare": "husky install"
1213
},
1314
"dependencies": {
1415
"@yarnpkg/lockfile": "^1.1.0",
1516
"ejs": "^3.1.8",
1617
"express": "^4.18.1",
17-
"microformats-parser": "^1.5.2",
18-
"undici": "^5.6.1"
18+
"microformats-parser": "^1.5.2"
19+
},
20+
"devDependencies": {
21+
"husky": ">=6",
22+
"lint-staged": ">=10",
23+
"prettier": "^3.0.3"
24+
},
25+
"lint-staged": {
26+
"*.{js,css,md}": "prettier --write"
1927
}
2028
}

0 commit comments

Comments
 (0)