1
0
Fork 0
mirror of https://github.com/imjasonh/terraform-playground synced 2026-07-17 22:54:49 +00:00

demo using ESM with KV and R2

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2023-08-12 10:40:58 -04:00
parent 1e82289e81
commit f5ae8b5cb2
Failed to extract signature
2 changed files with 28 additions and 6 deletions

View file

@ -1,6 +1,16 @@
addEventListener("fetch", (event) => {
console.log("Hello from the service worker!");
let value = KV.get("foo");
event.respondWith(new Response(value,
{ headers: { "content-type": "text/plain" } }));
});
export default {
async fetch(request, env, ctx) {
let value = await env.KV.get("foo");
await env.KV.put("foo", value + "r");
let obj = await env.R2.get("foo");
if (!obj) {
obj = "ba";
} else {
obj = await obj.text();
}
await env.R2.put("foo", obj + "r");
return new Response(`${value} / ${obj}`);
},
};