Skip to content
Snippets Groups Projects
Unverified Commit a011780f authored by Kristian Freeman's avatar Kristian Freeman Committed by GitHub
Browse files

Cache schema using KV (#10083)

* Cache schema using KV

* stringify schema object
parent 6f160096
Branches
No related tags found
No related merge requests found
export async function onRequestGet() {
export async function onRequestGet(context) {
const cachedSchema = await context.env.API_DOCS_KV.get("schema", "json")
if (cachedSchema) {
return new Response(JSON.stringify(cachedSchema), {
headers: { 'Content-type': 'application/json' }
})
}
const schemaUrl = "https://raw.githubusercontent.com/cloudflare/api-schemas/main/openapi.json"
const req = new Request(schemaUrl)
......@@ -62,6 +69,9 @@ export async function onRequestGet() {
response = new Response(JSON.stringify(sortedSchema), {
headers: { 'Content-type': 'application/json' }
})
const expirationTtl = 60 * 60
await context.env.API_DOCS_KV.put("schema", JSON.stringify(sortedSchema), { expirationTtl })
}
return response
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment