R2 via workers returnind undefined for list, get, delete and put requests

I have everythin in 'modules' to organize the code better
index.js
pageHandler.js
corsHandler.js

I created a bucket so that the static and dynamic html files can be fetched
When I call the pageHandler from index I send the request, env and ctx as parameters,however it seems to not pass the object at all


import {corsOptions} from "./corsHandler";

const handlePages=async (request, env, ctx, trigger='404') => {
    switch (true) {
        case "200": {
            return new Response(JSON.stringify({res: "Hi"}), {status: 200})
        }
        default :
            return await handle404Pages(request, env, ctx)
    }
}


const returnPage=async (htmlResponse, request, status=200) => {
    switch (request.method) {
        case 'GET':
            return new Response(htmlResponse, {
                status: status,
                headers: {
                    'Content-Type': 'text/html'
                }
            });
        default:
            const responseData={
                "status": "Not Found"
            }
            const jsonResponse=JSON.stringify(responseData)
            // Return JSON response with appropriate CORS headers
            return new Response(jsonResponse, corsOptions(request), 404);

    }
}

const getPageR2=async (env, page) => {
    return await env.STORE.get(`src/html/${page}.html`)
}

async function handle404Pages(request, env, ctx) {

    const ContactMeObject=JSON.stringify(env.CONTACTME);
    console.log(ContactMeObject)
    const object=await getPageR2(env, "404")
    if (object === null) {
        return new Response('Object Not Found', {status: 404});
    }
    console.log(JSON.stringify(object))
    const htmlContent=object
        .replace('{{URL}}', ContactMeObject['WHERE'])
        .replace('{{CONTACT}}', ContactMeObject[ContactMeObject['WHERE']]);
    return await returnPage(htmlContent, request, 404)
}


export {handlePages}
Was this page helpful?