Fetch origin using worker endless loop

I'm trying to do something using a worker on a route before passing the request on (to cache, origin, etc.). I think I should be able to just call fetch() on the original request, but that puts me in an endless loop of the worker calling itself.
Can someone hit me on the head real quick? :NotLikeThis:
export default {
async fetch(request, env, ctx) {
// Do something else
// ..

// Fetch origin
return await this.fetch(request)
},
};
export default {
async fetch(request, env, ctx) {
// Do something else
// ..

// Fetch origin
return await this.fetch(request)
},
};
12 Replies
ItsWendell
ItsWendell•4mo ago
Is your worker setup as a worker route through Websites -> your.domain -> Worker routes? Also did you confirm that the request.url is the one that you expect it to be? This won't work I think on something like the .workers.dev domains.
spdermn
spdermnOP•4mo ago
Yes, it's setup like that request.url is what I expect
spdermn
spdermnOP•4mo ago
No description
No description
spdermn
spdermnOP•4mo ago
you can see it looping in the console
ItsWendell
ItsWendell•4mo ago
Is your origin hosted on cloudflare?
spdermn
spdermnOP•4mo ago
proxied, and html cached on cloudflare
spdermn
spdermnOP•4mo ago
Stack Overflow
Run Cloudflare Workers while maintaining cached HTML delivery
I'm caching HTML content on Cloudflare and would like to replace client-side pixel tracking with pure server-side tracking - without any client-side initiation. I would like to use Cloudflare Worke...
ItsWendell
ItsWendell•4mo ago
What might be interesting to run is to go to your cloudflare account dashboard and go to Trace (beta), maybe that might reveal something interesting!
spdermn
spdermnOP•4mo ago
No much help sadly
spdermn
spdermnOP•4mo ago
No description
spdermn
spdermnOP•4mo ago
yep just figured it out lol autocomplete got me haha fet + enter does this.fetch() :lul:
ItsWendell
ItsWendell•4mo ago
OOhhhhh hahaha, ofc 🤯
Want results from more Discord servers?
Add your server