-
-
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
adds cloudflare cf object to platform property #9978
Conversation
🦋 Changeset detectedLatest commit: 43ca9ec 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 |
thank you! |
super nice, just found this via the changelog and before I've worked around this by adding cf to locals in hooks via a custom union type but now, this is much better |
Sorry for spamming this thread but I've just tried to access export const load = async ({ locals, platform }) => {
...
return { cf: platform?.cf }
}
@Spioune did I use it as intended? |
@205g0 From what I see there is no error in your code. Make sure you use the latest version of I just created a new project with |
Thanks for your reply:
It was.
Did you deploy it to production/Cloudflare (because you can get this cf object only when deployed to CF)? If yes, do you have a Cloudflare preview link? And deployed a +page.svelte which exposes the cf object? As said, it didn't work for me--cf was undefined. I still use my locals work-around in hooks because it's more DRY for my use case. But for others driving by, it would be great if this feature is really working. |
Ok, I've just tried it another time and it works now, seems I did something wrong the othre time. |
Cloudflare provides a CF object on the incoming Request (docs)
The CF object contains geolocation info similar to Vercel's X-Vercel-IP-*.
Since it is specific to Cloudflare, it is preferable to add it to the platform property.
Without this CF object, it is currently not possible to get the user location (edge function location)
It will also close this issue #5447