-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: allow additional handlers to be exported by adapter-cloudflare #13739
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
base: main
Are you sure you want to change the base?
feat: allow additional handlers to be exported by adapter-cloudflare #13739
Conversation
🦋 Changeset detectedLatest commit: c9cd1de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This is no longer a draft as all test, lints and checks should now be passing. This PR replaces #13207 as the two Cloudflare adapters have now been merged into one. The approach here is the same as in #13207: the Cloudflare adapter optionally takes a path to a file which exports anything that can be exported from a Cloudflare Worker, except for the I have intentionally not followed what the Node adapter does (generate two files: one which exports the SvelteKit handler, and one which runs that handler as a server, allowing users to optionally import the handler and run it in their own server) as I don’t think there is a strong reason to do it for this adapter, given a Cloudflare Worker is just an export handler and not a server itself. Correct me if I’m wrong, but most of the use cases of a custom fetch handler can be realised inside SvelteKit itself, specifically inside the |
For reference, the following handlers will work as properties on the default export, alongside The following functionality is available as classes which can be exported as named exports from the file: |
closes #10117
closes #1712
Cloudflare Workers allows for handlers to be exported from a worker as methods on an object exported as a default export. Currently, adapter-cloudflare-workers exports a fetch handler method, but there is no way to add other handler methods, such as a scheduled or queue handler. This functionality was requested just over a year ago in #10496.
This PR adds a configuration option for @sveltejs/adapter-cloudflare to provide a file whose exports get added to the default option exported by the worker the adapter generates. The fetch handler does not get overridden.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits