Skip to content

Commit fd6a3f1

Browse files
committed
fix: get ip address
1 parent 3800e92 commit fd6a3f1

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/app/api/report-tag/route.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { connectToDatabase } from "@/lib/database/mongoose";
33
import TagReport from "@/db/tagReport";
44
import { Ratelimit } from "@upstash/ratelimit";
55
import { redis } from "@/lib/utils/redis";
6-
import { exams } from "@/components/select_options";
6+
7+
const exams: string[] = ["CAT-1", "CAT-2", "FAT", "Model CAT-1", "Model CAT-2", "Model FAT"]
78

89
interface ReportedFieldInput {
910
field: string;
@@ -27,7 +28,15 @@ function getRateLimit(){
2728
});
2829
}
2930
function getClientIp(req: Request & { ip?: string}): string {
30-
return req.ip ?? "127.0.0.1";
31+
const xff = req.headers.get("x-forwarded-for");
32+
if (typeof xff === "string" && xff.length > 0) {
33+
return xff.split(",")[0]?.trim()??"";
34+
}
35+
const xri = req.headers.get("x-real-ip");
36+
if (typeof xri === "string" && xri.length > 0) {
37+
return xri;
38+
}
39+
return "0.0.0.0";
3140
}
3241

3342
export async function POST(req: Request & { ip?: string }) {

0 commit comments

Comments
 (0)