Francisco
Francisco
CDCloudflare Developers
Created by Francisco on 2/15/2024 in #general-help
Do bulk redirect ignoring trailing slash
Hello, I have created a Bulk Redirect List with the following record https://example.com/articles/12345/article-title/ --> https://example.com/articles/67890/article-title which is working perfectly, but I would like it to also work to redirect without considering the trailing slash of the Source URL. Is this possible by changing some setting or do I need to add another record to the list for this case?
2 replies
CDCloudflare Developers
Created by Francisco on 1/8/2024 in #workers-help
Worker threw exception / Body has already been used
Hello! I created this Worker to detect when a page on my website has the string data-error="404" in the body and set the appropriate HTTP response code. I also created a Worker Route for mysite.tld/* and this works perfectly for error pages that have the data-error string, but for "normal" pages the error "Error 1101 Worker threw exception" is generated. In the Worker's Quick Edit console I also see the error "Uncaught (in response) TypeError: Body has already been used. It can only be used once. Use tee() first if you need to read it twice.", but I really couldn't wrap my head around resolving this. Any help?
export default {
async fetch(request) {
const response = await fetch(request)
const body = await response.text()
if (body.includes("html data-error=\"404\"")) {
return new Response(body, {
status: 404,
statusText: "Not Found",
headers: response.headers
})
} else {
return response
}
}
};
export default {
async fetch(request) {
const response = await fetch(request)
const body = await response.text()
if (body.includes("html data-error=\"404\"")) {
return new Response(body, {
status: 404,
statusText: "Not Found",
headers: response.headers
})
} else {
return response
}
}
};
6 replies