Skip to content
Discussion options

You must be logged in to vote

@WilliamScott-AdventGX @r-ae-i Thanks for bringing this up! We've made an update that should populate the X-Forwarded-For header with the request's client IP correctly.

Here's an example snippet on how you can detect user's location based on IP in an edge function:

import { serve } from "https://deno.land/std@0.131.0/http/server.ts"

function ips(req: Request) {
  return req.headers.get("x-forwarded-for")?.split(/\s*,\s*/);
}

serve(async (req) => {
  const clientIps = ips(req) || [''];
  const res = await fetch(`https://ipinfo.io/${clientIps[0]}?token=XXXX`, {
      headers: { 'Content-Type': 'application/json'}});
  const { city, country } = await res.json();

  return new Response(
  …

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@idevelop
Comment options

@laktek
Comment options

@torkleyy
Comment options

Answer selected by laktek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
5 participants