Skip to content

Instantly share code, notes, and snippets.

@Ivshti
Created May 14, 2019 19:52
Show Gist options
  • Save Ivshti/4632556a6d7619de05393440e2789d20 to your computer and use it in GitHub Desktop.
Save Ivshti/4632556a6d7619de05393440e2789d20 to your computer and use it in GitHub Desktop.
cf worker for last-videos catalog (metasDetailed)
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const urls = [
"https://v3-channels.strem.io/meta/channel/yt_id%3AUCa90xqK2odw1KV5wHU9WRhg/lastVideos=1.json",
"https://v3-channels.strem.io/meta/channel/yt_id%3AUCa90xqK2odw1KV5wHU9WRhg/lastVideos=1.json"
]
const allRequests = urls.map(async u => {
const response = await fetch(u)
const { meta } = await response.json()
return meta
})
const resp = { metasDetailed: await Promise.all(allRequests) }
// @TODO consider headers from the first response
const headers = { 'content-type': 'application/json; charset=utf-8' }
return new Response(JSON.stringify(resp), { headers })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment