mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-08 21:04:03 +01:00
add simple caching
This commit is contained in:
parent
ee91c4795d
commit
94b802a7a3
@ -6,8 +6,10 @@ const webtask = require('webtask-tools')
|
|||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
let cached
|
||||||
|
|
||||||
|
const getData = res => {
|
||||||
// Just chained callbacks in lack of proper async/await support on webtask.io
|
// Just chained callbacks in lack of proper async/await support on webtask.io
|
||||||
app.get('/', (req, res) => {
|
|
||||||
// Gitcoin bounties
|
// Gitcoin bounties
|
||||||
request('https://gitcoin.co/api/v0.1/bounties/', (error, response, body) => {
|
request('https://gitcoin.co/api/v0.1/bounties/', (error, response, body) => {
|
||||||
if (error) return error
|
if (error) return error
|
||||||
@ -29,10 +31,20 @@ app.get('/', (req, res) => {
|
|||||||
const bountiesNetwork = JSON.parse(body)
|
const bountiesNetwork = JSON.parse(body)
|
||||||
holder.bountiesNetwork = bountiesNetwork.results
|
holder.bountiesNetwork = bountiesNetwork.results
|
||||||
|
|
||||||
|
cached = holder
|
||||||
|
|
||||||
// Send final response
|
// Send final response
|
||||||
res.send(holder)
|
res.send(holder)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
if (cached) {
|
||||||
|
res.send(cached)
|
||||||
|
} else {
|
||||||
|
getData(res)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = webtask.fromExpress(app)
|
module.exports = webtask.fromExpress(app)
|
||||||
|
Loading…
Reference in New Issue
Block a user