-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_check.js
54 lines (43 loc) · 1.1 KB
/
status_check.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const assert = require('assert');
const https = require('https');
const daysBetween = function( date1, date2 ) {
//Get 1 day in milliseconds
var one_day=1000*60*60*24;
// Convert both dates to milliseconds
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
// Calculate the difference in milliseconds
var difference_ms = date2_ms - date1_ms;
// Convert back to days and return
return Math.round(difference_ms/one_day);
};
const run = async () => {
var https = require('https');
var options = {
host: 'alexjpaz.com',
method: 'get',
path: '/'
};
await new Promise((resolve, reject) => {
var req = https.request(options, function (res) {
const cert = res.socket.getPeerCertificate();
const valid_to = new Date(cert.valid_to);
const now = new Date();
try {
assert(daysBetween(now, valid_to) > 30);
resolve();
} catch(e) {
reject(e);
}
});
req.end();
});
};
exports.handler = async () => {
try {
await run();
} catch(e) {
throw e;
// do some alerting here
}
};