tangled
alpha
login
or
join now
bad-example.com
/
spacedust-utils
6
fork
atom
demos for spacedust
6
fork
atom
overview
issues
pulls
pipelines
healthcheck pings
bad-example.com
7 months ago
7b4561ea
7a975634
+20
1 changed file
expand all
collapse all
unified
split
server
index.js
+20
server/index.js
···
3
import { createRemoteJWKSet } from 'jose';
4
import fs from 'node:fs';
5
import { randomBytes } from 'node:crypto';
0
6
import webpush from 'web-push';
7
import { DB } from './db.js';
8
import { connectSpacedust } from './notifications.js';
···
26
return secrets;
27
}
28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
29
const main = env => {
30
if (!env.ADMIN_DID) throw new Error('ADMIN_DID is required to run');
31
const adminDid = env.ADMIN_DID;
···
53
const port = parseInt(env.PORT ?? 8000, 10);
54
55
const allowedOrigin = env.ALLOWED_ORIGIN ?? 'http://127.0.0.1:5173';
0
0
0
56
57
server(secrets, jwks, allowedOrigin, whoamiHost, db, updateSubs, push, adminDid).listen(
58
port,
···
3
import { createRemoteJWKSet } from 'jose';
4
import fs from 'node:fs';
5
import { randomBytes } from 'node:crypto';
6
+
import https from 'node:https';
7
import webpush from 'web-push';
8
import { DB } from './db.js';
9
import { connectSpacedust } from './notifications.js';
···
27
return secrets;
28
}
29
30
+
function startHealthcheckPing(endpoint) {
31
+
const next = () => setTimeout(() => startHealthcheckPing(endpoint), 90 * 1000);
32
+
33
+
https
34
+
.get(endpoint, res => {
35
+
if (res.statusCode !== 200) console.warn('non-200 health check response', res.statusCode);
36
+
res
37
+
.on('data', () => {})
38
+
.on('end', next);
39
+
})
40
+
.on('error', err => {
41
+
console.warn('healthcheck request errored', err);
42
+
next();
43
+
});
44
+
}
45
+
46
const main = env => {
47
if (!env.ADMIN_DID) throw new Error('ADMIN_DID is required to run');
48
const adminDid = env.ADMIN_DID;
···
70
const port = parseInt(env.PORT ?? 8000, 10);
71
72
const allowedOrigin = env.ALLOWED_ORIGIN ?? 'http://127.0.0.1:5173';
73
+
74
+
if (env.HEALTHCHECK) startHealthcheckPing(env.HEALTHCHECK);
75
+
else console.warn('no HEALTHCHECK in env, not sending healthcheck pings');
76
77
server(secrets, jwks, allowedOrigin, whoamiHost, db, updateSubs, push, adminDid).listen(
78
port,