Skip to content

Instantly share code, notes, and snippets.

@rita3ko
Created October 16, 2019 23:50
Show Gist options
  • Save rita3ko/dd8fa92d8a730332b8bb692081fb8c31 to your computer and use it in GitHub Desktop.
Save rita3ko/dd8fa92d8a730332b8bb692081fb8c31 to your computer and use it in GitHub Desktop.
Page views Cloudflare Worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
let count = await counter.get('views')
counter.put('views', parseInt(count)+1)
return new Response(`views: ${count}`, {status: 200})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment