Report this

What is the reason for this report?

Cant get cf-ipcountry with Nuxt App

Posted on March 7, 2021

I’m using my Nuxt app with cloudflare to get users geo location country (cf-ipcountry) using a middleware. I’ve recently switched to DigitalOcean from Google Cloud App Engine and seems like I’m unable to request cf-ipcountry.

Do you guys have any idea why? Or how i can fix it?

Here’s a sample code:

export default async function ({ req,res }) {
  try {
        const loc = req.headers['cf-ipcountry']
        if (loc === undefined) {
            console.log("Unknown")
        } else {
            console.log(loc)
        }
    }
    catch (err) {
        console.log(err)
    }
}

Checking the request headers in the DigitalOcean App Logs, I cant even see cf-ipcountry.

Would really appreciate any help. Thanks!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This comment has been deleted

Heya,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

Cloudflare’s ‘cf-ipcountry’ header is specific to traffic that goes through the Cloudflare network. If you have recently moved your application from Google Cloud App Engine to DigitalOcean and you are not seeing the ‘cf-ipcountry’ header anymore, it’s likely that your traffic is not going through Cloudflare.

You need to ensure that your domains DNS settings are pointed to Cloudflare nameservers. Also, make sure Cloudflare is set to proxy traffic for your domain (orange cloud icon in DNS settings).

If your settings are correct and you’re still having issues, you might want to reach out to Cloudflare support, as they might be better equipped to help with this specific header issue.

For more information about DigitalOcean App platform configuration, please refer to the DigitalOcean App Platform Documentation.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.