emrgilhzp: Proxy the home feed with cursor paging
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { SESSION_COOKIE } from "@/lib/cookie";
|
||||
import { clampLimit, getHomeFeedPage } from "@/lib/feed";
|
||||
|
||||
// GET /api/feed?cursor=<nextCursor>&limit=<n>
|
||||
// Same-origin proxy for the Minnect home feed. Returns { items, nextCursor }.
|
||||
// 401 { error: "sign_in" } when the session is missing or dead.
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const sessionId = req.cookies.get(SESSION_COOKIE)?.value;
|
||||
const cursor = req.nextUrl.searchParams.get("cursor") || null;
|
||||
const limit = clampLimit(req.nextUrl.searchParams.get("limit"));
|
||||
|
||||
const result = await getHomeFeedPage(sessionId, cursor, limit);
|
||||
if (!result.ok) {
|
||||
return NextResponse.json({ error: result.error }, { status: result.status });
|
||||
}
|
||||
return NextResponse.json({ items: result.items, nextCursor: result.nextCursor });
|
||||
}
|
||||
Reference in New Issue
Block a user