17 lines
465 B
TypeScript
17 lines
465 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const ipAddress =
|
|
request.headers.get("x-forwarded-for")?.split(",")[0] || "unknown";
|
|
|
|
const ipv4Regex = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/;
|
|
const match = ipAddress.match(ipv4Regex);
|
|
|
|
const normalizedIp = match ? match[1] : ipAddress;
|
|
|
|
return NextResponse.json({
|
|
originalIp: ipAddress,
|
|
normalizedIp: normalizedIp,
|
|
});
|
|
}
|