Is there something obviously wrong with this function that would cause a 503/1019 error? I have a st

Is there something obviously wrong with this function that would cause a 503/1019 error? I have a static nuxt 3 cf pages project that works until I deploy this code in a
/functions/[[catchall]].js
. This code logic works when deployed separately as a cf worker but not when translated to a cf pages function.

export async function onRequest(context) {
    const { request } = context;
    let url = new URL(request.url);

    // Set the hostname to the original site
    url.hostname = "example.com";
    let ogResponse = fetch(url, request);

    // Now set the hostname to the Cloudflare Pages version
    url.hostname = "test-branch.example.pages.dev";
    const cfPagesResponse = await fetch(url, request);

    // Return the Cloudflare Pages response if it's not a 404
    if (cfPagesResponse.status !== 404) {
        return cfPagesResponse;
    }

    // Otherwise, return the original site's response
    return await ogResponse;
}
Was this page helpful?