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
manishrc
manishrcOP13mo ago
I can see it in the logs, but dont' have access to it within the route handler.
No description
James
James13mo ago
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.
manishrc
manishrcOP12mo ago
Got it, thank you.
atgctg
atgctg12mo ago
(commenting to get notified on any future updates on this)
gui.ohm
gui.ohm10mo ago
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
['accept', 'accept-encoding', 'accept-language', 'cf-connecting-ip', 'cf-ipcountry', 'cf-ray', 'cf-visitor', 'connection', 'host', 'origin', 'referer', 'sec-ch-ua', 'sec-ch-ua-mobile', 'sec-ch-ua-platform', 'sec-fetch-dest', 'sec-fetch-mode', 'sec-fetch-site', 'user-agent', 'x-forwarded-proto', 'x-real-ip', 'x-vercel-ip-city', 'x-vercel-ip-country', 'x-vercel-ip-country-region', 'x-vercel-ip-latitude', 'x-vercel-ip-longitude', 'x-vercel-sc-host']
['accept', 'accept-encoding', 'accept-language', 'cf-connecting-ip', 'cf-ipcountry', 'cf-ray', 'cf-visitor', 'connection', 'host', 'origin', 'referer', 'sec-ch-ua', 'sec-ch-ua-mobile', 'sec-ch-ua-platform', 'sec-fetch-dest', 'sec-fetch-mode', 'sec-fetch-site', 'user-agent', 'x-forwarded-proto', 'x-real-ip', 'x-vercel-ip-city', 'x-vercel-ip-country', 'x-vercel-ip-country-region', 'x-vercel-ip-latitude', 'x-vercel-ip-longitude', 'x-vercel-sc-host']
James
James10mo ago
we set the x-vercel values based on the request.cf properties so that they match the same behaviour as a deployment to vercel
gui.ohm
gui.ohm10mo ago
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?
James
James10mo ago
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
Want results from more Discord servers?
Add your server