Skip to content

Commit

Permalink
handler
Browse files Browse the repository at this point in the history
  • Loading branch information
devjiwonchoi committed Sep 16, 2024
1 parent 8c7fc46 commit 6349cb4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-nocheck
/* eslint-disable */
import { type NextRequest, NextResponse } from "next/server";

export function GET(request: NextRequest) {
const { city, country, region, latitude, longitude } = request.geo;
return NextResponse.json({ city, country, region, latitude, longitude });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-nocheck
/* eslint-disable */
import { type NextRequest, NextResponse } from "next/server";

import { geolocation } from "@vercel/functions";

export function GET(request: NextRequest) {
const { city, country, region, latitude, longitude } = geolocation(request);
return NextResponse.json({ city, country, region, latitude, longitude });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-nocheck
/* eslint-disable */
import { type NextRequest, NextResponse } from "next/server";

function getGeo(request: NextRequest) {
return request.geo
}

export function GET(request: NextRequest) {
const geo = getGeo(request)
return NextResponse.json({ geo });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-nocheck
/* eslint-disable */
import { type NextRequest, NextResponse } from "next/server";

import { geolocation } from "@vercel/functions";

function getGeo(request: NextRequest) {
return geolocation(request);
}

export function GET(request: NextRequest) {
const geo = getGeo(request)
return NextResponse.json({ geo });
}


13 changes: 6 additions & 7 deletions packages/next-codemod/transforms/next-request-geo-ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ export default function (fileInfo: FileInfo, api: API) {
}
})

if (
ipAccesses.length > 0 ||
need_import_geolocation =
need_import_geolocation ||
geoAccesses.length > 0 ||
ipDestructuring.length > 0 ||
geoDestructuring.length > 0
) {
need_import_geolocation = true
need_import_ipAddress = true
}
need_import_ipAddress =
need_import_ipAddress ||
ipAccesses.length > 0 ||
ipDestructuring.length > 0
}

if (need_import_geolocation || need_import_ipAddress) {
Expand Down

0 comments on commit 6349cb4

Please sign in to comment.