desloppify: code health overhaul plus abuse hardening (140 green, strict 87.2)
Build & Push / Lint & Build (pull_request) Failing after 52s
Build & Push / Build & Push Image (pull_request) Skipped
Build & Push / Trigger Deploy (pull_request) Skipped

Honest baseline after removing 45 gaming suppressions. Structural: lib/game plus root hooks extraction, CORS origin echo, DEV_ORIGINS layering. Fixes: error-cause binding, discord 5xx split, null-cache guard, co-located tests, rejecting-fetch coverage, naming and typing cleanup, socket controller, cache bound, cascade helpers, latch resets. Hardening: per-IP rate limit on API routes, deterministic-miss UX, retry cooldown plus cap. Suite 140 green, build plus lint clean.
This commit is contained in:
fristy committed 2026-09-11 23:54:59 +03:00
1 parent 7d6d31265b
commit 864b9226fc
78 files changed
+4908 -1430

No files matched your search

+26 -31
View File
@@ -1,37 +1,32 @@
import { NextResponse } from "next/server";
import { corsHeaders, forbidden, isAllowedOrigin } from "@/lib/api-cors";
import { getDiscordAppInfo } from "@/lib/lanyard";
import { getDiscordAppInfo } from "@/lib/game/discord-app";
import {
invalidIdResponse,
jsonErrorWithCors,
jsonWithCors,
parseAppId,
requestOrigin,
} from "@/lib/api-route";
import { warnDev } from "@/lib/log";
import type { NextResponse } from "next/server";
export async function OPTIONS(request: Request) {
if (!isAllowedOrigin(request)) {
return forbidden();
export async function GET(
request: Request,
context: { params: Promise<{ id: string }> },
): Promise<NextResponse> {
const origin = requestOrigin(request);
const id = await parseAppId(context);
if (!id) {
return invalidIdResponse(origin);
}
return new NextResponse(null, {
status: 204,
headers: {
...corsHeaders(),
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Max-Age": "86400",
},
});
}
export async function GET(request: Request, context: { params: Promise<{ id: string }> }) {
if (!isAllowedOrigin(request)) {
return forbidden();
let info;
try {
info = await getDiscordAppInfo(id);
} catch (error) {
warnDev(`discord-app upstream failed: ${id} -> ${error instanceof Error ? error.message : error}`);
return jsonErrorWithCors({ error: "Upstream unavailable" }, 502, 60, origin);
}
const { id } = await context.params;
if (!/^\d+$/.test(id)) {
return NextResponse.json({ error: "Invalid application id" }, { status: 400 });
}
const info = await getDiscordAppInfo(id);
if (!info) {
return NextResponse.json({ error: "Application not found" }, { status: 404 });
return jsonErrorWithCors({ error: "Application not found" }, 404, 60, origin);
}
return NextResponse.json(info, {
headers: {
"Cache-Control": "public, s-maxage=86400, stale-while-revalidate=86400",
...corsHeaders(),
},
});
return jsonWithCors(info, 86400, origin);
}