schwartzmj
05/13/2023, 8:44 PMschwartzmj
05/13/2023, 8:45 PMjavascript
addEventListener("fetch", event => {
console.log('start')
// If this request is coming from image resizing worker,
// avoid causing an infinite loop by resizing it again.
// In other words, this worker tries to fetch the source image from
// the website, but this worker gets called again instead.
if (/auto-image/.test(event.request.headers.get("via"))) {
console.log('matched via header: ', event.request.headers.get('via'))
return fetch(event.request)
}
if (/imagedelivery.net/.test(event.request.headers.get("cf-worker"))) {
console.log('matched cf-worker header: ', event.request.headers.get('cf-worker'))
return
// return fetch(event.request)
}
// Now you can safely use image resizing here
event.passThroughOnException();
console.log('respondWith about to be called')
event.respondWith(handleRequest(event.request))
});
schwartzmj
05/13/2023, 8:46 PMhandleRequest
, i'm issuing a fetch request to Cloudflare Images to perform manipulations on an image. if the image doesn't exist in my account (i get a 404), i upload the image and then re-do the first fetchschwartzmj
05/13/2023, 8:46 PMschwartzmj
05/13/2023, 8:47 PMconsole.log('matched cf-worker header'...
runs. as in, it's the very first thing to get called other than console.log('start')
schwartzmj
05/13/2023, 8:48 PMif
statement might run when i'm doing the CF Images API requests later on in the workerschwartzmj
05/13/2023, 8:49 PMimagedelivery.net
header check. then it runs again doing the event.respondWith...
schwartzmj
05/13/2023, 8:50 PMvia
header check never seems to run, but i thought i was getting infinite loops before adding thatschwartzmj
05/13/2023, 9:10 PM