Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CheckURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if (opts[0].startsWith("--") || opts[0].startsWith("/")) { //if it's a commn
// });
printJSON(opts[1])

} else if (opts[0] == "--ignore") {
readUrlsWithoutIgnore(opts[1], opts[2]);
} else {
console.log("Invalid input, please enter '--v' for version or filename for testing.");
}
Expand All @@ -59,6 +61,51 @@ function printResult() {
console.log(resultList)
}

function readUrlsWithoutIgnore(ignoreFile, file) {
fs.readFile(ignoreFile, (err, data) => {
if (err) {
console.log(err);
} else {
var strData = data.toString();
var ignoreURLs = strData.match(regexp);
ignoreURLs = [...new Set(ignoreURLs)];

fs.readFile(file, (err, data) => {
if (err) {
console.log(err);
} else {
var strData = data.toString();
var URLs = strData.match(regexp);
URLs = [...new Set(URLs)];

for (let i = 0; i < URLs.length; i++) {
let isIgnore = false;
for (let j = 0; j < ignoreURLs.length; j++) {
if (URLs[i].startsWith(ignoreURLs[j])) {
isIgnore = true;
}
}

if (!isIgnore) {
request.get({ uri: URLs[i], timeout: 5000 }, function (err, res, body) {
if (err) {
console.log(colors.yellow(`${err} ${URLs[i]}`));
} else if (res.statusCode == 200) {
console.log("This page is ok: " + URLs[i].green)
} else if (res.statusCode == 404 || res.statusCode == 400) {
console.log("Can not find this page: " + URLs[i].red)
} else {
console.log("Unkown status: " + URLs[i].grey)
}
})
}
}
}
})
}
})
}

function printJSON(filename) {
fs.readFile(filename, (err, data) => { //read the file
if (err) {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ npm i --save colors request
2. allow passing directory paths vs. file paths, and recursively process all children under that directory
3. add support for more HTTP result codes. For example, redirects with 301, 307, 308 (i.e., follow the redirect to the new location)
4. add support for timeouts, DNS resolution issues, or other server errors when accessing a bad URL. A bad domain, URL, or server shouldn't crash your tool.
5. add feature for ignore url(s). If you enter 'Webpage-status-checking-tool --ignore [ignore url list filename] [url list filename]', this tool test all urls without ignore urls.

## Instructions

Expand Down
6 changes: 6 additions & 0 deletions ignore-urls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore All Seneca College URLs
https://senecacollege.ca
# Ignore all Learn@Seneca URLs
https://learn.senecacollege.ca/
#Ignore all s9y.org
http://s9y.org