maximillian
04/08/2022, 9:03 AMxHyroM
04/08/2022, 10:57 AMIsaac McFadyen | YYZ01
04/08/2022, 12:11 PMIsaac McFadyen | YYZ01
04/08/2022, 12:12 PMxHyroM
04/08/2022, 12:16 PMsimpson
04/08/2022, 1:54 PMkian
04/08/2022, 1:55 PMsimpson
04/08/2022, 2:01 PMaddEventListener('fetch', event => {
const { request } = event;
const { url } = request;
if (request.method === 'POST') {
return event.respondWith(handleRequest(request));
} else if (request.method === 'GET') {
return event.respondWith(new Response(`The request was a GET`));
}
});
/**
* Many more examples available at:
* https://developers.cloudflare.com/workers/examples
* @param {Request} request
* @returns {Promise<Response>}
*/
async function handleRequest(request) {
const authToken = await request.headers.get("authorization");
const formData = await request.formData();
const oldImageId = formData.get("old_image_id");
formData.delete("old_image_id");
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/63d719b39174eb1cfc9816ccf9a7512f/images/v1`,
{
method: "POST",
body: formData,
headers: {
Authorization: `Bearer ######`,
},
}
);
await fetch(
`https://api.cloudflare.com/client/v4/accounts/63d719b39174eb1cfc9816ccf9a7512f/images/v1/${oldImageId}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer #######`,
},
}
);
return response;
}
simpson
04/08/2022, 6:32 PMHazard
04/08/2022, 11:26 PMEvаn
04/08/2022, 11:28 PMEvаn
04/08/2022, 11:28 PMHazard
04/08/2022, 11:28 PMHazard
04/08/2022, 11:29 PMHazard
04/08/2022, 11:29 PMHazard
04/08/2022, 11:30 PMHazard
04/08/2022, 11:30 PMEvаn
04/08/2022, 11:31 PMadapter-cloudflare
yep, it builds it into .svelte-kit/cloudflare
Hazard
04/08/2022, 11:31 PMEvаn
04/08/2022, 11:32 PMsvelte-kit dev
, no need to buildEvаn
04/08/2022, 11:32 PMHazard
04/08/2022, 11:32 PMEvаn
04/08/2022, 11:33 PMEvаn
04/08/2022, 11:33 PMsvelte-kit dev
ts
/** For development */
async function getDummyStore() {
const { Miniflare } = await import("miniflare")
const mf = new Miniflare({
script: "",
kvNamespaces: ["STORE"],
kvPersist: true
})
return mf.getKVNamespace("STORE")
}
Hazard
04/08/2022, 11:34 PMSeb
04/09/2022, 8:03 AMsimpson
04/09/2022, 12:34 PMStew
04/09/2022, 3:25 PMresponse.headers.set('Cloudflare-CDN-Cache-Control', 'public, max-age=120')
Which works fine, I see the age header on subsequent refreshes increment up to 120 then the page is fetched from origin again.
But if I purge the cache, both `by url `and purge everything
, it still increments up to 120 before fetching from origin again. I'd expect it to fetch from origin within the ~30s purge window.
The only thing I notice is this response header cf-cache-status: DYNAMIC
, this should be HIT
right? (not sure why it's showing dynamic when it does cache successfully, my function just returns the current timestamp so I know it's working fine)Stew
04/09/2022, 3:46 PMIsaac McFadyen | YYZ01
04/09/2022, 4:00 PM