Skip to content

Instantly share code, notes, and snippets.

@Ebrahim-Ramadan
Created September 13, 2024 11:14
Show Gist options
  • Save Ebrahim-Ramadan/fb546261e39c6c3289fdd172cef71d91 to your computer and use it in GitHub Desktop.
Save Ebrahim-Ramadan/fb546261e39c6c3289fdd172cef71d91 to your computer and use it in GitHub Desktop.
Geolocation helper function for nextjs server components
import { headers } from "next/headers";
export function geoLocation() {
const headersList = headers();
return {
ip: headersList.get("x-real-ip"),
country: headersList.get("x-vercel-ip-country"),
city: headersList.get("x-vercel-ip-city"),
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment