Skip to content

Commit 77b9c0e

Browse files
committed
Merge branch 'release/1.0.4' into main
* release/1.0.4: Bump version. Add better request headers; correct logic on fetch.
2 parents b4d3261 + d2a70f0 commit 77b9c0e

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const port = process.env.PORT || 9000;
88

99
function htmlToMf2(url, html, res) {
1010
mf2.get({ baseUrl: url, html }, (err, data) => {
11+
const body = err || data;
1112
res
1213
.header("content-type", "application/json; charset=UTF-8")
13-
.send(JSON.stringify(err || data, null, 2));
14+
.send(JSON.stringify(body, null, 2));
1415
});
1516
}
1617

@@ -19,8 +20,16 @@ app.use(express.static("public"));
1920
app.get("/", async (req, res) => {
2021
if (req.query.url) {
2122
const url = req.query.url;
22-
const { body } = await undici.request(url);
23-
htmlToMf2(url, body.text(), res);
23+
const { body } = await undici.request(url, {
24+
maxRedirections: 2,
25+
headers: {
26+
accept: "text/html, text/mf2+html",
27+
},
28+
method: "GET",
29+
});
30+
const text = await body.text();
31+
console.log(text);
32+
htmlToMf2(url, text, res);
2433
} else {
2534
res.render("index.html.ejs", {
2635
version: `${pkg.version} (lib: ${mf2.version})`,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "microformats-website-node",
33
"description": "A website written using Node to demonstrate Microformats2 usage",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"engines": {
66
"node": "17.x",
77
"yarn": "1.x"

0 commit comments

Comments
 (0)