Skip to content

Edge Function: Cannot get geo informations since v12 #31191

@judewang

Description

@judewang

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:
vercel/examples#24
vercel/examples#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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions