1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-11-22 09:47:05 +01:00
community-numbers/api/index.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-06-16 11:12:27 +02:00
import { logError } from './utils'
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'
//
// 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 12:32:47 +02:00
let response = {}
2020-06-16 12:32:47 +02:00
try {
const github = await fetchGitHubRepos()
response = { ...response, github }
} catch (error) {
logError(error.message)
}
2020-06-16 12:32:47 +02:00
try {
const bounties = await fetchBounties()
response = { ...response, bounties }
} catch (error) {
logError(error.message)
}
2020-06-16 12:32:47 +02:00
try {
const medium = await fetchMedium()
response = { ...response, medium }
} catch (error) {
logError(error.message)
}
2020-06-16 12:32:47 +02:00
try {
const twitter = await fetchTwitter()
response = { ...response, twitter }
} catch (error) {
logError(error.message)
}
2020-06-16 12:32:47 +02:00
try {
const telegram = await fetchTelegram()
response = { ...response, telegram }
} catch (error) {
logError(error.message)
}
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 12:32:47 +02:00
res.json(response)
}