So I have a react static page, built with vite(rollup), I need to create a functions folder and list

So I have a react static page, built with vite(rollup), I need to create a functions folder and listen to fetch events like this:
export default {
  async fetch(request, env) {
    const url = new URL(request.url);

    if (url.pathname.startsWith('/api/')) {
      const apiRequest = new Request(
        `https://your-worker-url.com${url.pathname}`,
        request
      );
      return env.MY_WORKER_SERVICE.fetch(apiRequest);
    }

    return env.ASSETS.fetch(request);
  },
};

});

In this example, MY_WORKER_SERVICE is the name I gave to the service binding in the Cloudflare Pages dashboard.
using the SERVICE and in the static code just request to localhost/api.....?
Was this page helpful?