下面是第13点,希望加上APIC末点代码<>/api/getIP。
route.js
file is in the /app/api/getIP/route.js
.
我尝试了几种方式,但都没有奏效。 我尝试使用<条码>request-ip 来登上正本,但返回<代码>null<>。
Here is my code:
import { NextResponse } from "next/server";
import requestIp from "request-ip";
export async function GET(req) {
const detectedIp = requestIp.getClientIp(req);
const data = {
ok: true,
ip: detectedIp,
userAgent: req.headers.get("user-agent"),
};
return new NextResponse(JSON.stringify(data, null, 2));
}
我在访问时收到这一答复:
{
"ok": true,
"ip": null,
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
}