See the Pen MyJSON Deno KV by John Doe (@04) on CodePen.
http://myjson.com の代替え品を作りました!
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"
const kv = await Deno.openKv()
serve(async (req: Request) => {
const key = new URL(req.url).pathname.slice(1)
if (req.method === "GET") {
const { value } = await kv.get([ key ])
const init = {
headers: {
"content-type": "application/json; charset=UTF-8",
"Access-Control-Allow-Origin": "*"
}
}
return new Response(value, init)
} else if (req.method === "POST") {
kv.set([ key ], await req.text())
}
return new Response('', { headers: { "Access-Control-Allow-Origin": "*" } })
})