Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 0 additions & 71 deletions web/app/api/visit/rate-limit.test.ts

This file was deleted.

98 changes: 0 additions & 98 deletions web/app/api/visit/rate-limit.ts

This file was deleted.

27 changes: 2 additions & 25 deletions web/app/api/visit/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// drifted (accepted any http:// host instead of https-with-loopback-only).
import { leanValidate } from "@visitportal/spec/lean-validator";
import { NextResponse } from "next/server";
import { check as rateLimitCheck } from "./rate-limit";
import { guardUrl } from "./ssrf-guard";

// GET /api/visit?url=<portal-url>
Expand Down Expand Up @@ -62,19 +61,8 @@ export async function GET(req: Request): Promise<NextResponse<VisitResponse>> {
const { searchParams } = new URL(req.url);
const target = searchParams.get("url");

// Rate limit per client IP before any outbound work. When Upstash env vars
// are absent (dev), check() returns ok:true with an empty headers map.
const ip = getClientIp(req);
const rl = await rateLimitCheck(ip);
const respond = (body: VisitResponse, status: number): NextResponse<VisitResponse> => {
const res = NextResponse.json<VisitResponse>(body, { status });
for (const [k, v] of Object.entries(rl.headers)) res.headers.set(k, v);
return res;
};

if (!rl.ok) {
return respond({ ok: false, stage: "url", error: "rate limit exceeded" }, 429);
}
const respond = (body: VisitResponse, status: number): NextResponse<VisitResponse> =>
NextResponse.json<VisitResponse>(body, { status });

if (!target) {
return respond({ ok: false, stage: "url", error: "missing 'url' query parameter" }, 400);
Expand Down Expand Up @@ -132,17 +120,6 @@ export async function GET(req: Request): Promise<NextResponse<VisitResponse>> {

// ---------- helpers ----------

function getClientIp(req: Request): string {
const xff = req.headers.get("x-forwarded-for");
if (xff) {
const first = xff.split(",")[0]?.trim();
if (first) return first;
}
const xri = req.headers.get("x-real-ip")?.trim();
if (xri) return xri;
return "anon";
}

interface FetchOk {
ok: true;
text: string;
Expand Down
2 changes: 0 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"test": "vitest run"
},
"dependencies": {
"@upstash/ratelimit": "^2.0.5",
"@upstash/redis": "^1.34.3",
"@visitportal/spec": "workspace:^0.1.8",
"ipaddr.js": "^2.2.0",
"next": "^15.1.4",
Expand Down
Loading