-
Notifications
You must be signed in to change notification settings - Fork 1
/
testserver.js
57 lines (45 loc) · 1.31 KB
/
testserver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var express = require('express')
var cors = require('cors')
var bodyParser = require('body-parser')
var read = require('node-readability')
var app = express()
app.use(cors())
app.use(bodyParser.json({limit: '50mb'}))
var port = 5000
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function (req, res) {
res.sendStatus(200)
})
// POST method route
app.post('/index', function (req, res) {
try {
read(req.body.html, readablePage)
res.sendStatus(200)
} catch (err) {
console.log(err)
res.sendStatus(400)
}
})
function readablePage(err, article, meta) {
// Main Article
lines = article.content.split("\n");
lines.forEach((line) => {
// if (line.length > 10) {
console.log("==============================================="+line);
// }
});
// console.log("===============================================")
// Title
console.log(article.title);
// HTML Source Code
// console.log(article.html);
// DOM
// console.log(article.document);
// Response Object from Request Lib
// console.log(meta);
// Close article to clean up jsdom and prevent leaks
article.close();
};
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})