mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-11-25 03:20:17 +01:00
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const ms = require('ms')
|
|
const { logError } = require('./util/logger')
|
|
|
|
const fetchGitHubRepos = require('./networks/github')
|
|
const fetchBounties = require('./networks/bounties')
|
|
const fetchMedium = require('./networks/medium')
|
|
const fetchTwitter = require('./networks/twitter')
|
|
|
|
let cacheGithub = null
|
|
let cacheBounties = null
|
|
let cacheMedium = null
|
|
let cacheTwitter = null
|
|
|
|
//
|
|
// Create the response
|
|
//
|
|
module.exports = async (req, res) => {
|
|
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET')
|
|
|
|
try {
|
|
if (!cacheGithub || Date.now() - cacheGithub.lastUpdate > ms('5m')) {
|
|
cacheGithub = await fetchGitHubRepos()
|
|
}
|
|
|
|
if (!cacheBounties || Date.now() - cacheBounties.lastUpdate > ms('5m')) {
|
|
cacheBounties = await fetchBounties()
|
|
}
|
|
|
|
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
|
|
cacheMedium = await fetchMedium()
|
|
}
|
|
|
|
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
|
|
cacheTwitter = await fetchTwitter()
|
|
}
|
|
} catch (error) {
|
|
logError(error.message)
|
|
}
|
|
|
|
res.end(JSON.stringify({
|
|
github: cacheGithub,
|
|
bounties: cacheBounties,
|
|
medium: cacheMedium,
|
|
twitter: cacheTwitter
|
|
}))
|
|
}
|