diff --git a/libs/live-fns/github.js b/libs/live-fns/github.js index d36aad4..085b4e0 100644 --- a/libs/live-fns/github.js +++ b/libs/live-fns/github.js @@ -1,4 +1,5 @@ const axios = require('../axios.js') +const token = process.env.GH_TOKEN // https://developer.github.com/v3/repos/ @@ -18,8 +19,10 @@ module.exports = async function (topic, ...args) { } async function release (user, repo, channel) { - const endpoint = `https://api.github.com/repos/${user}/${repo}/releases` - const logs = await axios.get(endpoint).then(res => res.data) + const url = `https://api.github.com/repos/${user}/${repo}/releases` + const headers = token && { 'Authorization': `token ${token}` } + + const logs = await axios({ url, headers }).then(res => res.data) const [latest] = logs const stable = logs.find(log => !log.prerelease) diff --git a/libs/serve-status.js b/libs/serve-status.js index 01ed6f2..26b4f1e 100644 --- a/libs/serve-status.js +++ b/libs/serve-status.js @@ -5,8 +5,15 @@ module.exports = async function (req, res) { const [ githubRateLimit ] = await Promise.all([ - axios('https://api.github.com/rate_limit').then(res => res.data.resources) + getGithubRateLimit() ]) send(res, 200, { githubRateLimit }) } + +function getGithubRateLimit () { + const url = 'https://api.github.com/rate_limit' + const token = process.env.GH_TOKEN + const headers = token && { 'Authorization': `token ${token}` } + return axios({ url, headers }).then(res => res.data.resources) +} diff --git a/now.json b/now.json index 350a8fa..212f39a 100644 --- a/now.json +++ b/now.json @@ -10,6 +10,9 @@ "service.js", "libs" ], + "env": { + "GH_TOKEN": "@badgen-gh-token" + }, "engines": { "node": "^10.0.0" }