Created
October 16, 2019 23:50
-
-
Save rita3ko/dd8fa92d8a730332b8bb692081fb8c31 to your computer and use it in GitHub Desktop.
Page views Cloudflare Worker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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