mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-07 20:35:30 +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()
|
||||
|
||||
// Just chained callbacks in lack of proper async/await support on webtask.io
|
||||
app.get('/', (req, res) => {
|
||||
let cached
|
||||
|
||||
const getData = res => {
|
||||
// Just chained callbacks in lack of proper async/await support on webtask.io
|
||||
// Gitcoin bounties
|
||||
request('https://gitcoin.co/api/v0.1/bounties/', (error, response, body) => {
|
||||
if (error) return error
|
||||
@ -29,10 +31,20 @@ app.get('/', (req, res) => {
|
||||
const bountiesNetwork = JSON.parse(body)
|
||||
holder.bountiesNetwork = bountiesNetwork.results
|
||||
|
||||
cached = holder
|
||||
|
||||
// Send final response
|
||||
res.send(holder)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
if (cached) {
|
||||
res.send(cached)
|
||||
} else {
|
||||
getData(res)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = webtask.fromExpress(app)
|
||||
|
Loading…
Reference in New Issue
Block a user