-
Notifications
You must be signed in to change notification settings - Fork 31
/
healthcheck.ts
62 lines (53 loc) · 1.37 KB
/
healthcheck.ts
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
55
56
57
58
59
60
61
62
import axios from 'axios'
/* eslint-disable no-console */
const checkUrl = async (url) => {
try {
const response = await axios({
method: 'get',
url,
timeout: 10000,
})
return response.status === 200
} catch (err) {
console.error('Error in checkUrl', err)
return false
}
}
const checkMarketplace = async () => {
const result = await checkUrl('http://localhost:3333')
if (result) {
console.log('Marketplace is UP')
return true
}
console.error('Marketplace is DOWN')
return false
}
const checkLogin = async () => {
const result = await checkUrl('http://localhost:3333/login')
if (result) {
console.log('Login is UP')
return true
}
console.error('Login is DOWN')
return false
}
const checkAll = async () => {
const results = await Promise.all([checkMarketplace(), checkLogin()])
// Return false even if a single check fails
return !results.includes(false)
}
checkAll()
.then((result) => {
if (result) {
console.log('Platform is UP')
process.exit(0)
} else {
console.error('Platform is DOWN')
process.exit(1)
}
})
.catch((error) => {
console.error('Could not run checks!')
console.error(error)
process.exit(1)
})