-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
adapter-cloudflare: IncomingRequestCfProperties
are not part of the types on RequestEvent.request
#5447
Comments
I think option 2 is preferable. Not all requests come from Cloudflare — it a page requests some data via kit/packages/kit/src/runtime/server/page/load_node.js Lines 214 to 215 in a3288db
In either case, |
Just stumbled upon the missing Personally I'd say option 1 is more "natural" as that's where you'd expect it to be coming from Workers, as I just did and also that's where the property is already anyway, though if it's too hard to add the types 😬 2 coupled with docs would be better than no types. Also I found the readme already confusing as I was expecting to destructure Anyway, I was pretty excited how quickly and smoothly I just deployed a Kit skeleton to Workers 🥳 |
Closed by #9978 🚀 |
Describe the bug
When deploying to Cloudflare Pages (or Workers) via
@sveltejs/adapter-cloudflare
, Cloudflare adds a customcf
property to all requests that contains a lot of useful information about the request.The property is called
IncomingRequestCfProperties
and is documented here:https://developers.cloudflare.com/workers/runtime-apis/request/#incomingrequestcfproperties
The property is actually available on the request object in SvelteKit (when deployed, not locally of course), but the typings for the event doesn't include it
RequestEvent.request
, and the docs doesn't describe how to fix the types.Reproduction
Minimal repo here: https://github.com/JReinhold/sveltekit-missing-cf
With emphasis on this line: https://github.com/JReinhold/sveltekit-missing-cf/blob/main/src/routes/index.ts#L6
Deployed to Cloudflare Pages here: https://sveltekit-missing-cf.pages.dev
(remember, this doesn't do anything locally, which is why I've deployed it as well)
Real-life usage can be seen at JReinhold/reinhold.is#39 and in action at https://reinhold.is
Logs
No response
System Info
Severity
annoyance
Additional Information
I see two possible solutions to this:
@sveltejs/adapter-cloudflare
modify the types on the request to includeIncomingRequestCfProperties
.cf
property toplatform
, and update the types accordingly.Option 2 seems more in line with SvelteKit's general MO of adding platform-specific things to
platform
and it is more explicit, but doesn't match Cloudflare's documentation on the matter. Option 1 is the opposite.I'm open to open a PR for either of the solutions but would like a maintainer to decide which is best for SvelteKit.
Relevant work: #5386, #5081
The text was updated successfully, but these errors were encountered: