Skip to content

Allow custom worker script when deploying to Cloudflare #13692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
victormihalache opened this issue Apr 8, 2025 · 0 comments
Open

Allow custom worker script when deploying to Cloudflare #13692

victormihalache opened this issue Apr 8, 2025 · 0 comments

Comments

@victormihalache
Copy link

Describe the problem

When deploying to Cloudflare there's no way to customize the worker. This means no Durable Objects, no RPC methods, no CRON jobs, just the fetch() handler.

Describe the proposed solution

Currently when building with the adapter-cloudflare the entry Worker file gets generated at .svelte-kit/cloudflare/_worker.js. At its core it just exports the fetch handler for the Worker.

// other stuff...

var worker_default = {
  async fetch(req, env, context) {
    // request handling...
  }
};
export {
  worker_default as default
};

Other frameworks like React Router create a workers folder in the root directory of the project containing app.ts—the worker script. It looks like this:

import { createRequestHandler } from "react-router";

declare module "react-router" {
  export interface AppLoadContext {
    cloudflare: {
      env: Env;
      ctx: ExecutionContext;
    };
  }
}

const requestHandler = createRequestHandler(
  () => import("virtual:react-router/server-build"),
  import.meta.env.MODE
);

export default {
  async fetch(request, env, ctx) {
    return requestHandler(request, {
      cloudflare: { env, ctx },
    });
  },
} satisfies ExportedHandler<Env>;

React Router basically provides a handler you can use in your worker in the fetch(). Why wouldn't SvelteKit be able to provide something similar?

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants