Skip to content

Commit f759727

Browse files
committed
Add better request headers; correct logic on fetch.
1 parent c37714a commit f759727

1 file changed

Lines changed: 12 additions & 3 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})`,

0 commit comments

Comments
 (0)