adapter-cloudflare: IncomingRequestCfProperties
are not part of the types on RequestEvent.request
#5447
Milestone
IncomingRequestCfProperties
are not part of the types on RequestEvent.request
#5447
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: