Skip to content
Merged
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
18 changes: 4 additions & 14 deletions app/api/comments/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import { NextRequest, NextResponse } from "next/server";
import { createHash } from "crypto";
import { createSupabaseServerClient } from "@/lib/supabase/server";
import { createSupabaseAdminClient } from "@/lib/supabase/admin";
import { consumeSharedRateLimit } from "@/lib/rate-limit/shared";

function hashIp(ip: string): string {
const pepper = process.env.IP_HASH_PEPPER ?? "default-pepper";
return createHash("sha256")
.update(ip + pepper)
.digest("hex");
}

function getIp(req: NextRequest): string {
return req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() ?? "unknown";
}
import { hashIp, getClientIp } from "@/lib/utils/hash";

interface CommentBody {
post_id?: unknown;
Expand Down Expand Up @@ -65,7 +54,7 @@ export async function POST(req: NextRequest) {
);
}

const ip = getIp(req);
const ip = getClientIp(req.headers);
const ip_hash = hashIp(ip);

const rateLimit = await consumeSharedRateLimit(
Expand Down Expand Up @@ -97,7 +86,8 @@ export async function POST(req: NextRequest) {

if (error) throw error;
return NextResponse.json({ comment: data }, { status: 201 });
} catch {
} catch (err) {
console.error("[comments] error:", err);
return NextResponse.json(
{ error: "Failed to post comment" },
{ status: 500 },
Expand Down
2 changes: 1 addition & 1 deletion app/robots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function robots(): MetadataRoute.Robots {
rules: {
userAgent: "*",
allow: "/",
disallow: ["/admin", "/api/", "/edit/"],
disallow: ["/admin/", "/api/", "/edit/", "/status/", "/unsubscribe/"],
},
sitemap: `${siteUrl}/sitemap.xml`,
};
Expand Down
Loading