Created
June 14, 2021 00:36
-
-
Save leaysgur/a9e62afebb76ad0f2b6e6b27c17c5fc9 to your computer and use it in GitHub Desktop.
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)) | |
}) | |
let id = 0; | |
async function handleRequest(request) { | |
const params = new URL(request.url).searchParams; | |
const mode = params.get("mode") || "0"; | |
if (mode === "list") { | |
const list = await KV.list(); | |
console.log("LIST: %o", list.keys); | |
return new Response(JSON.stringify(list.keys)); | |
} | |
if (mode === "put") { | |
await KV.put(id++, "OK"); | |
console.log("PUT: %s", id); | |
return new Response(); | |
} | |
const value = await KV.get(mode); | |
console.log("GET: %s => %s", mode, value); | |
return new Response(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment