question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Edge Function: Cannot get geo informations since v12

See original GitHub issue

What version of Next.js are you using?

12.0.2

What version of Node.js are you using?

16.6.0

What browser are you using?

Brave, Safari

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

By logging the request object, we can confirm that the geo and ip are undefined.

CleanShot 2021-11-09 at 15 53 05

The DEPLOYED example of the geolocation usage still works correctly, but the other new examples deployed by clicking the “Deploy” button on the README page cannot work correctly. https://github.com/vercel/examples/tree/main/edge-functions/geolocation

There were two issues opened for this bug: https://github.com/vercel/examples/issues/24 https://github.com/vercel/examples/issues/34

Expected Behavior

It should be possible to get the geolocation data from request object like in the example.

To Reproduce

import { NextRequest, NextResponse } from 'next/server';

export async function middleware(req: NextRequest) {
  console.log(req);

  const { geo } = req;
  const { nextUrl: url, geo } = req
  const country = geo.country || 'US'

  url.searchParams.set('country', country)

  return NextResponse.rewrite(url)
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Pieparkercommented, Dec 5, 2021

geo won’t work locally because your address is 127.0.0.1 (ref). You’ll want to try spinning it up on an online dev env!

0reactions
balazsorban44commented, Jan 27, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restrictions on edge functions - Amazon CloudFront
The following topics describe the restrictions that apply to CloudFront Functions and Lambda@Edge. Some restrictions apply to all edge functions, ...
Read more >
Next.js v12 - Building a Geolocation Country Block App w
... power of Vercel Edge Functions Building a Geolocation Country Block App and how them allow us to ... Your browser can't play...
Read more >
Vercel Edge Functions with Next.js - Ahmad Awais
Vercel's Edge Functions to be used with Next.js (v12) announced today at ... getting geolocation from an IP Address, and user-agent info.
Read more >
Edge Functions – Vercel Docs
Edge Functions are defined in JavaScript or TypeScript files in your codebase. You can specify a Function's region by exporting a config object...
Read more >
[aws-lambda] CurrentVersion not available for imported ...
General Issue The Question I'm only able to get .currentVersion on the new lambda function, but not on the imported one.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found