Wrap the loop in an async function then put it in a waitUntil
Wrap the loop in an async function then put it in a waitUntil
14400





Hacker News
•10/26/21, 5:41 PM



should've gone for foundation dbThe magic with KV is its unlimited scale and getting faster the more requests you give it, it's made for read-heavy cases, like for example Cloudflare Pages uses it
concat(“/v1”, http.request.uri.path) and ended up with /v1/v1/<original_req_path>/v1 works but doesn't feel robust enough)Typescript
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();
const encoder = new TextEncoder();
const response = new Response(readable, {
headers: {
...corsHeaders,
},
});
(async () => {
try {
for await (const chunk of completions) {
const content = chunk['choices'][0].delta.content!;
const encodedMessage = encoder.encode(content);
writer.write(encodedMessage);
}
writer.close();
} catch (e) {
console.error(e);
// writer.abort(e);
return new Response('bad bad error', { headers: corsHeaders });
}
})();
return response;concat(“/v1”, http.request.uri.path)/v1/v1/<original_req_path>/v1 let value = await env.KV.get("index.html", {cacheTtl: 86400, type: "stream" });
return new Response(value, {
headers: {
"content-type": "text/html"
}
})