34 lines
873 B
JavaScript
34 lines
873 B
JavaScript
import { Readability } from "@mozilla/readability";
|
|
import { JSDOM } from "jsdom";
|
|
import express from "express";
|
|
import morgan from "morgan";
|
|
import bodyParser from "body-parser";
|
|
import createDOMPurify from "dompurify";
|
|
|
|
const app = express();
|
|
app.use(morgan('combined'));
|
|
app.use(bodyParser.text({
|
|
type: "text/html",
|
|
}));
|
|
|
|
app.get('/status', (req, res) => {
|
|
res.type('text/plain').send('OK');
|
|
});
|
|
|
|
app.post('/readability', (req, res) => {
|
|
const doc = new JSDOM(req.body, {
|
|
url: req.params.url,
|
|
});
|
|
const reader = new Readability(doc.window.document);
|
|
const article = reader.parse();
|
|
const purifier = createDOMPurify(doc.window);
|
|
const cleaned = purifier.sanitize(article.content);
|
|
res.send(cleaned);
|
|
});
|
|
|
|
const port = process.env.PORT || 4001;
|
|
// only accept local requests
|
|
app.listen(port, "localhost", () => {
|
|
console.log(`listening on port ${port}`);
|
|
});
|