mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-11-22 09:47:00 +01:00
site: move github fetching to serverless function
This commit is contained in:
parent
54277db52c
commit
2a72eb085c
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,4 +6,5 @@ dist
|
|||||||
coverage
|
coverage
|
||||||
.next
|
.next
|
||||||
out
|
out
|
||||||
.env
|
.env
|
||||||
|
.now
|
1
site/.env.example
Normal file
1
site/.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
GITHUB_TOKEN=
|
18
site/api/github.js
Normal file
18
site/api/github.js
Normal 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
10
site/package.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "blowfish-site",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.19.2",
|
||||||
|
"dotenv": "^8.2.0"
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +1,11 @@
|
|||||||
async function init() {
|
async function init() {
|
||||||
const release = await getLatestRelease()
|
const response = await fetch('/api/github')
|
||||||
|
const release = await response.json()
|
||||||
replaceDom(release)
|
replaceDom(release)
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', () => init())
|
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) {
|
function getDownloads(release) {
|
||||||
const downloads = release.assets
|
const downloads = release.assets
|
||||||
.filter(
|
.filter(
|
||||||
|
Loading…
Reference in New Issue
Block a user