Skip to content

Commit

Permalink
Replace undici with native fetch; add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
aimee-gm committed Sep 14, 2023
1 parent 1b5f4bd commit 7d29d03
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 25 deletions.
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const express = require("express");
const { mf2 } = require("microformats-parser");
const undici = require("undici");
const pkg = require("./package.json");
const app = express();
const port = process.env.PORT || 9000;
Expand Down Expand Up @@ -36,15 +35,15 @@ app.use(express.static("public"));
app.get("/", async (req, res) => {
if (req.query.url) {
const url = req.query.url;
const { body } = await undici.request(url, {
maxRedirections: 2,
await fetch(url, {
headers: {
accept: "text/html, text/mf2+html",
},
method: "GET",
}).then(async (response) => {
const html = await response.text();
htmlToMf2(url, html, res);
});
const text = await body.text();
htmlToMf2(url, text, res);
} else {
res.render("index.html.ejs", {
version: `${pkg.version} (lib: ${mf2version})`,
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
"yarn": "1.x"
},
"scripts": {
"start": "node index.js"
"start": "node index.js",
"prepare": "husky install"
},
"dependencies": {
"@yarnpkg/lockfile": "^1.1.0",
"ejs": "^3.1.8",
"express": "^4.18.1",
"microformats-parser": "^1.5.2",
"undici": "^5.6.1"
"microformats-parser": "^1.5.2"
},
"devDependencies": {
"husky": ">=6",
"lint-staged": ">=10",
"prettier": "^3.0.3"
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
}
Loading

0 comments on commit 7d29d03

Please sign in to comment.