mirror of
https://github.com/M4X809/list-of-lp.git
synced 2025-12-25 11:12:48 +00:00
Enhance GET route in favico API with debugging logs
- Added console logs to track the URL, lastImage, selected album, and image path during the GET request process. - Improved visibility into the API's behavior for debugging purposes.
This commit is contained in:
parent
dd9460ca0f
commit
7461820ede
1 changed files with 5 additions and 4 deletions
|
|
@ -5,9 +5,11 @@ import { cookies } from "next/headers";
|
|||
// Absolute URL redirect is required by Next.js middleware & API routes
|
||||
export async function GET(request: NextRequest) {
|
||||
const url = new URL(request.url);
|
||||
console.log("🚀 ~ route.tsx:8 ~ GET ~ url:", url);
|
||||
const randParam = url.searchParams.get("rand");
|
||||
const cookieStore = await cookies();
|
||||
const lastImage = cookieStore.get("lastImage")?.value;
|
||||
console.log("🚀 ~ route.tsx:12 ~ GET ~ lastImage:", lastImage);
|
||||
|
||||
// Get all available albums, excluding the previous image
|
||||
const availableAlbums = lastImage ? albums.filter((album) => album.image !== lastImage) : albums;
|
||||
|
|
@ -20,15 +22,14 @@ export async function GET(request: NextRequest) {
|
|||
randomIndex = Math.floor(Math.random() * availableAlbums.length);
|
||||
}
|
||||
const album = availableAlbums[randomIndex];
|
||||
|
||||
console.log("🚀 ~ route.tsx:25 ~ GET ~ album:", album);
|
||||
// Ensure image path starts with a slash
|
||||
const imagePath = album.image.startsWith("/") ? album.image : `/${album.image}`;
|
||||
|
||||
console.log("🚀 ~ route.tsx:29 ~ GET ~ imagePath:", imagePath);
|
||||
// Build absolute URL for the redirect
|
||||
const { nextUrl } = request;
|
||||
const absoluteUrl = `${nextUrl.protocol}//${nextUrl.host}${imagePath}`;
|
||||
|
||||
cookieStore.set("lastImage", album.image);
|
||||
console.log("🚀 ~ route.tsx:33 ~ GET ~ absoluteUrl:", absoluteUrl);
|
||||
|
||||
return NextResponse.redirect(absoluteUrl, 307);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue