-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwatcher.js
30 lines (26 loc) · 944 Bytes
/
watcher.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
const https = require('https');
const data = require('./data.js');
const checkLinks = async (links) => {
const requests = links.map(link => {
return new Promise((resolve) => {
https.get(link.src, { method: 'HEAD' }, (res) => {
const lastModified = res.headers['last-modified'];
if (lastModified && lastModified !== link["last-modified"]) {
console.log(`${link.text}: Last Modified: ${lastModified} (Expected: ${link["last-modified"]})`);
}
resolve();
}).on('error', (e) => {
console.error(`Error fetching ${link.src}: ${e.message}`);
resolve();
});
});
});
await Promise.all(requests);
};
const main = async () => {
await checkLinks(data.links);
await checkLinks(data.cssLinks);
console.log('All checks completed.');
process.exit();
};
main();