more buxfix

This commit is contained in:
Daniel
2022-04-27 16:49:47 +04:30
parent c85f5a3324
commit 2511082f14
3 changed files with 18 additions and 13 deletions
+15 -9
View File
@@ -22,16 +22,22 @@ app.post('/post', (req, res) => {
let title;
const pageToVisit = req.body.link;
request(pageToVisit, (error, response, body) => {
if(response.statusCode === 200) {
// Parse the document body
const $ = cheerio.load(body);
try {
if(response.statusCode === 200) {
// Parse the document body
const $ = cheerio.load(body);
req.body.title = $('title').text();
insertDoc(req.body);
} else {
req.body.title = null;
insertDoc(req.body);
}
req.body.title = $('title').text();
insertDoc(req.body);
} else {
req.body.title = null;
insertDoc(req.body);
}
} catch (error) {
console.log(error);
req.body.title = null;
insertDoc(req.body);
}
});
});