1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-12-26 14:47:53 +01:00

site: move github fetching to serverless function

This commit is contained in:
Matthias Kretschmann 2020-03-06 03:10:05 +01:00
parent 54277db52c
commit 2a72eb085c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 38 additions and 16 deletions

3
.gitignore vendored
View File

@ -6,4 +6,5 @@ dist
coverage
.next
out
.env
.env
.now

5
now.json Normal file
View File

@ -0,0 +1,5 @@
{
"env": {
"GITHUB_TOKEN": "@github_token"
}
}

1
site/.env.example Normal file
View File

@ -0,0 +1 @@
GITHUB_TOKEN=

18
site/api/github.js Normal file
View File

@ -0,0 +1,18 @@
const axios = require('axios')
require('dotenv').config
module.exports = async (req, res) => {
try {
const response = await axios(
'https://api.github.com/repos/kremalicious/blowfish/releases/latest',
{
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`
}
}
)
res.status(200).send(response.data)
} catch (error) {
console.error(error.message)
}
}

10
site/package.json Normal file
View File

@ -0,0 +1,10 @@
{
"name": "blowfish-site",
"version": "1.0.0",
"author": "",
"license": "MIT",
"dependencies": {
"axios": "^0.19.2",
"dotenv": "^8.2.0"
}
}

View File

@ -1,24 +1,11 @@
async function init() {
const release = await getLatestRelease()
const response = await fetch('/api/github')
const release = await response.json()
replaceDom(release)
}
window.addEventListener('load', () => init())
async function getLatestRelease() {
const response = await fetch(
'https://api.github.com/repos/kremalicious/blowfish/releases/latest'
)
if (response.status !== 200) {
console.error(`Non-200 response code from GitHub: ${response.status}`)
return null
}
const json = await response.json()
return json
}
function getDownloads(release) {
const downloads = release.assets
.filter(