unpkg/server/CloudflareAPI.js
MICHAEL JACKSON 1173f91091 Require packages to be downloaded >= 100x/day
This should make it more difficult for people who are publishing
malicious packages to npm to get them on the CDN.
2017-08-16 23:04:59 -07:00

39 lines
817 B
JavaScript

require('isomorphic-fetch')
const invariant = require('invariant')
const CloudflareAPIURL = 'https://api.cloudflare.com'
const CloudflareEmail = process.env.CLOUDFLARE_EMAIL
const CloudflareKey = process.env.CLOUDFLARE_KEY
invariant(
CloudflareEmail,
'Missing the $CLOUDFLARE_EMAIL environment variable'
)
invariant(
CloudflareKey,
'Missing the $CLOUDFLARE_KEY environment variable'
)
function get(path, headers) {
return fetch(`${CloudflareAPIURL}/client/v4${path}`, {
headers: Object.assign({}, headers, {
'X-Auth-Email': CloudflareEmail,
'X-Auth-Key': CloudflareKey
})
})
}
function getJSON(path, headers) {
return get(path, headers).then(function (res) {
return res.json()
}).then(function (data) {
return data.result
})
}
module.exports = {
get,
getJSON
}