-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (29 loc) · 1.17 KB
/
index.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
const { crawlPage } = require('./crawl.js');
const { sortPages } = require('./report.js');
const {printReport} = require("./report");
const main = () => {
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
(function getValidInput () {
readline.question(`Which URL do you want to crawl?`, async urlName => {
const trimmedUrl = urlName.trim();
let validUrl = false;
if (trimmedUrl.includes(' ')) {
console.log('Please try again and enter only one URL');
getValidInput();
} else if (trimmedUrl.startsWith('http://') || trimmedUrl.startsWith('https://')) {
console.log(`Crawling ${trimmedUrl}...`);
readline.close();
const [pages, extPages] = await crawlPage(trimmedUrl, trimmedUrl, {}, {});
printReport(pages, extPages, trimmedUrl);
return;
} else {
console.log('Please try again and enter a valid URL that starts with http:// or https://');
getValidInput();
}
});
})();
}
main();