add loading indicator to the pagination
All checks were successful
Deploy SSR / deploy (push) Successful in 1m37s

This commit is contained in:
Lee
2024-09-12 11:35:37 +01:00
parent 99174e6299
commit f0dfbe78ea
5 changed files with 106 additions and 21 deletions

View File

@ -0,0 +1,47 @@
import { validateUrl } from "@/common/utils";
import ky from "ky";
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest) {
const url = request.nextUrl.searchParams.get("url");
if (url == null) {
return NextResponse.json({ error: "Missing URL. ?url=" }, { status: 400 });
}
if (!validateUrl(url)) {
return NextResponse.json({ error: "Invalid URL" }, { status: 400 });
}
try {
const response = await ky.get(url, {
next: {
revalidate: 30, // 30 seconds
},
});
const { status, headers } = response;
if (
!headers.has("content-type") ||
(headers.has("content-type") && !headers.get("content-type")?.includes("application/json"))
) {
return NextResponse.json({
error: "We only support proxying JSON responses",
});
}
const body = await response.json();
return NextResponse.json(body, {
status: status,
});
} catch (err) {
console.error(`Error fetching data from ${url}:`, err);
return NextResponse.json(
{ error: "Failed to proxy this request." },
{
status: 500,
headers: {
"Access-Control-Allow-Origin": "*",
},
}
);
}
}