Access to CF on Pages using Next.js
Does anyone know how to access the
cf
object in the headers when using next.js on CF?
I'm trying to access botManagement
and it's not set on the request.cf, nor it it part of the headers.8 Replies
I can see it in the logs, but dont' have access to it within the route handler.
Next.js would strip it off of the request object before your api route or middleware can access it I believe. We're currently looking at ways to expose the object to users.
Got it, thank you.
(commenting to get notified on any future updates on this)
I was poking around the request object and found those headers are passed through. Some of these can act as a subset of the cf object. Are these reliable / future proof ? @Better James
we set the x-vercel values based on the request.cf properties so that they match the same behaviour as a deployment to vercel
For the redundant fields do we favor
cf-
or x-vercel
. For instance cf-ipcountry
and x-vercel-ip-country
are the same. Is this documented?Whichever you prefer, but we will always populate the x-vercel ones with the req.cf data, so it's up to you which you want to use