forked from unpkg/unpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow-log.js
More file actions
46 lines (39 loc) · 1.13 KB
/
show-log.js
File metadata and controls
46 lines (39 loc) · 1.13 KB
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
require('isomorphic-fetch')
const invariant = require('invariant')
const CloudflareEmail = process.env.CLOUDFLARE_EMAIL
const CloudflareKey = process.env.CLOUDFLARE_KEY
const RayID = process.argv[2]
invariant(
CloudflareEmail,
'Missing the $CLOUDFLARE_EMAIL environment variable'
)
invariant(
CloudflareKey,
'Missing the $CLOUDFLARE_KEY environment variable'
)
invariant(
RayID,
'Missing the RAY_ID argument; use `heroku run node show-log.js RAY_ID`'
)
const getZones = (domain) =>
fetch(`https://api.cloudflare.com/client/v4/zones?name=${domain}`, {
method: 'GET',
headers: {
'X-Auth-Email': CloudflareEmail,
'X-Auth-Key': CloudflareKey
}
}).then(res => res.json())
.then(data => data.result)
const getLog = (zoneId, rayId) =>
fetch(`https://api.cloudflare.com/client/v4/zones/${zoneId}/logs/requests/${rayId}`, {
method: 'GET',
headers: {
'X-Auth-Email': CloudflareEmail,
'X-Auth-Key': CloudflareKey
}
}).then(res => res.status === 404 ? 'NOT FOUND' : res.json())
getZones('unpkg.com').then(zones => {
getLog(zones[0].id, RayID).then(entry => {
console.log(entry)
})
})