-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.js
executable file
·46 lines (37 loc) · 1.06 KB
/
client.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
#!/usr/bin/env node
import 'dotenv/config'
import { PunchmoleClient } from "./app.js";
const PUNCHMOLE_ENDPOINT_URL = process.env.PUNCHMOLE_ENDPOINT_URL || 'ws://localhost:10000/_punchmole'
const PUNCHMOLE_API_KEY = process.env.PUNCHMOLE_API_KEY
const DOMAIN = process.env.DOMAIN
const TARGET_URL = process.env.TARGET_URL || 'http://localhost:3000'
if(!DOMAIN) {
console.error('please specify a domain by using environment variable DOMAIN')
process.exit(1)
}
function wait(ms) {
return new Promise(r => setTimeout(r, ms));
}
function startClient() {
return new Promise((resolve) => {
const events = PunchmoleClient(
PUNCHMOLE_API_KEY,
DOMAIN,
TARGET_URL,
PUNCHMOLE_ENDPOINT_URL
)
events.on('close', () => {
resolve()
})
events.on('error', () => {
resolve()
})
})
}
setTimeout(async () => {
while(true) {
await startClient()
console.log(new Date(), 'restarting client in 500ms')
await wait(500)
}
}, 500)