Workers Routes Replacement

I want to create a workers route to:
a.com/api/sth
b.com/api/sth
c.com/api/sth
a.com/api/sth
b.com/api/sth
c.com/api/sth
if worker does not have response, then fetch origin a.com/api/sth as result.
how to write the fetch codes in the worker script?
3 Replies
kian
kian9mo ago
export default {
async fetch(req, env, ctx) {
// do whatever to generate a response

if (!response) {
return fetch(req);
}

return response;
}
}
export default {
async fetch(req, env, ctx) {
// do whatever to generate a response

if (!response) {
return fetch(req);
}

return response;
}
}
willin
willin9mo ago
but this api does not exists on b.com/c.com if i change req url hostname, can it work?
kian
kian9mo ago
Sure, just do fetch(url, req) where url is the a.com one
Want results from more Discord servers?
Add your server