2020-06-16 11:12:27 +02:00
|
|
|
import { logError } from './utils'
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 11:12:27 +02:00
|
|
|
import fetchGitHubRepos from './networks/github'
|
|
|
|
import fetchBounties from './networks/bounties'
|
|
|
|
import fetchMedium from './networks/medium'
|
|
|
|
import fetchTwitter from './networks/twitter'
|
|
|
|
import fetchTelegram from './networks/telegram'
|
|
|
|
import fetchDiscord from './networks/discord'
|
2020-06-16 10:48:36 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Create the response
|
|
|
|
//
|
|
|
|
export default async (req, res) => {
|
2020-06-16 12:32:47 +02:00
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET')
|
2020-06-16 17:04:26 +02:00
|
|
|
res.setHeader('Cache-Control', 'max-age=0, s-maxage=86400')
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
let response = {}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const github = await fetchGitHubRepos()
|
|
|
|
response = { ...response, github }
|
|
|
|
} catch (error) {
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const bounties = await fetchBounties()
|
|
|
|
response = { ...response, bounties }
|
|
|
|
} catch (error) {
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const medium = await fetchMedium()
|
|
|
|
response = { ...response, medium }
|
|
|
|
} catch (error) {
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const twitter = await fetchTwitter()
|
|
|
|
response = { ...response, twitter }
|
|
|
|
} catch (error) {
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const telegram = await fetchTelegram()
|
|
|
|
response = { ...response, telegram }
|
|
|
|
} catch (error) {
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
try {
|
|
|
|
const discord = await fetchDiscord()
|
|
|
|
response = { ...response, discord }
|
|
|
|
} catch (error) {
|
|
|
|
// fake fallback response cause puppeteer fails a lot
|
|
|
|
response = { ...response, discord: { members: '240' } }
|
|
|
|
logError(error.message)
|
|
|
|
}
|
2020-06-16 10:48:36 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
res.json(response)
|
2020-06-16 10:48:36 +02:00
|
|
|
}
|