Skip to content

Commit b4d3261

Browse files
committed
Merge branch 'release/1.0.3' into main
* release/1.0.3: Bump version Move common logic to a method, parse body
2 parents cde830f + d2f193f commit b4d3261

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
const express = require("express");
22
const mf2 = require("microformat-node");
33
const undici = require("undici");
4+
const querystring = require("querystring");
45
const pkg = require("./package.json");
56
const app = express();
67
const port = process.env.PORT || 9000;
78

9+
function htmlToMf2(url, html, res) {
10+
mf2.get({ baseUrl: url, html }, (err, data) => {
11+
res
12+
.header("content-type", "application/json; charset=UTF-8")
13+
.send(JSON.stringify(err || data, null, 2));
14+
});
15+
}
16+
817
app.set("view engine", "ejs");
918
app.use(express.static("public"));
1019
app.get("/", async (req, res) => {
1120
if (req.query.url) {
1221
const url = req.query.url;
1322
const { body } = await undici.request(url);
14-
mf2.get({ baseUrl: url, html: await body.text() }, (err, data) => {
15-
res.send(err || data);
16-
});
23+
htmlToMf2(url, body.text(), res);
1724
} else {
1825
res.render("index.html.ejs", {
1926
version: `${pkg.version} (lib: ${mf2.version})`,
2027
});
2128
}
2229
});
2330
app.post("/", (req, res) => {
24-
mf2.get({ baseUrl: req.body.url, html: req.body.html }, (err, data) => {
25-
res.send(err || data);
26-
});
31+
const qsBody = querystring.parse(req.body);
32+
htmlToMf2(qsBody.url, qsBody.html, res);
2733
});
2834

2935
app.listen(port, () => {

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.2",
4+
"version": "1.0.3",
55
"engines": {
66
"node": "17.x",
77
"yarn": "1.x"

0 commit comments

Comments
 (0)