Skip to content

Commit 76234b2

Browse files
Do not report URLs with HTTP code 200
1 parent abc78a1 commit 76234b2

7 files changed

Lines changed: 24 additions & 8 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ checkHttpStatus({
3939
'Accept': 'text/html',
4040
},
4141
},
42-
'sitemap': 'https://www.trunkcode.com/page-sitemap.xml'
42+
'sitemap': 'https://www.trunkcode.com/page-sitemap.xml',
43+
'skip200': true, // Do not report the URLs having HTTP code 200.
4344
});
4445
```
4546

@@ -62,6 +63,7 @@ checkHttpStatus({
6263
'Accept': 'text/html',
6364
},
6465
},
66+
'skip200': true, // Do not report the URLs having HTTP code 200.
6567
'urls': [
6668
'http://trunkcode.com/',
6769
'https://example.com/',

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ async function checkHttpStatus(config) {
1515
'csv',
1616
'xlsx',
1717
];
18+
var skip200 = false;
1819
var urlsList = [];
1920

21+
if (config.skip200) {
22+
skip200 = true;
23+
}
24+
2025
if (!config) {
2126
console.error('\x1b[31m%s\x1b[0m', 'Error: Missing required Parameters.');
2227
process.exit();
@@ -41,13 +46,17 @@ async function checkHttpStatus(config) {
4146
process.exit();
4247
}
4348

44-
const httpStatusList = await httpList(urlsList, config.options);
49+
const httpStatusList = await httpList(urlsList, config.options, skip200);
4550

4651
if (config.export && !config.export.format) {
4752
config.export.format = 'xlsx';
4853
}
4954

50-
if (config.export && allowedExportTypes.includes(config.export.format)) {
55+
if (skip200 && httpStatusList.length === 0) {
56+
// Add empty line
57+
console.log();
58+
console.log('\x1b[32m%s\x1b[0m', 'All the URLs are 200 and there is nothing to worry about!');
59+
} else if (config.export && allowedExportTypes.includes(config.export.format)) {
5160
const urlLength = Math.max(...urlsList.map((el) => el.length));
5261
const rowLength = {
5362
'errorMessage': 50,

lib/check-status-code.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function axiosRequest(urlToCheck, axiosOptions, redirect) {
8282
* Call main function to generate array with all the required information
8383
* and await until that all are not completed.
8484
*/
85-
async function checkStatusCode(urlToCheck, options) {
85+
async function checkStatusCode(urlToCheck, options, skip200) {
8686
const statusList = [];
8787

8888
var axiosOptions = {
@@ -111,7 +111,9 @@ async function checkStatusCode(urlToCheck, options) {
111111
statusList.push(row);
112112
});
113113
} else {
114-
statusList.push(statusArray);
114+
if (statusArray[2] !== 200 || !skip200) {
115+
statusList.push(statusArray);
116+
}
115117
}
116118

117119
return Promise.resolve(statusList);

lib/http-list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const checkStatusCode = require('./check-status-code');
55
/**
66
* List down all the URLs with the status code.
77
*/
8-
async function httpList(urlsList, configOptions) {
8+
async function httpList(urlsList, configOptions, skip200) {
99
const httpStatus = [];
1010
var combineResults = [];
1111

1212
for (const checkUrl of urlsList) {
13-
httpStatus.push(checkStatusCode(checkUrl, configOptions));
13+
httpStatus.push(checkStatusCode(checkUrl, configOptions, skip200));
1414
}
1515

1616
const httpResults = await Promise.all(httpStatus);

test/runkitExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ checkHttpStatus({
1212
'Accept': 'text/html',
1313
},
1414
},
15+
'skip200': true,
1516
'urls': [
1617
'https://trunkcode.com/',
1718
'https://example.com/',

test/sitemap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ checkHttpStatus({
1616
'Accept': 'text/html',
1717
},
1818
},
19-
'sitemap': 'https://www.trunkcode.com/page-sitemap.xml'
19+
'sitemap': 'https://www.trunkcode.com/page-sitemap.xml',
20+
'skip200': true,
2021
});

test/urls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ checkHttpStatus({
1616
'Accept': 'text/html',
1717
},
1818
},
19+
'skip200': true,
1920
'urls': [
2021
'https://trunkcode.com/',
2122
'https://example.com/',

0 commit comments

Comments
 (0)