mirror of
https://github.com/M4X809/list-of-lp.git
synced 2025-12-25 19: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
|
// Absolute URL redirect is required by Next.js middleware & API routes
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
|
console.log("🚀 ~ route.tsx:8 ~ GET ~ url:", url);
|
||||||
const randParam = url.searchParams.get("rand");
|
const randParam = url.searchParams.get("rand");
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
const lastImage = cookieStore.get("lastImage")?.value;
|
const lastImage = cookieStore.get("lastImage")?.value;
|
||||||
|
console.log("🚀 ~ route.tsx:12 ~ GET ~ lastImage:", lastImage);
|
||||||
|
|
||||||
// Get all available albums, excluding the previous image
|
// Get all available albums, excluding the previous image
|
||||||
const availableAlbums = lastImage ? albums.filter((album) => album.image !== lastImage) : albums;
|
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);
|
randomIndex = Math.floor(Math.random() * availableAlbums.length);
|
||||||
}
|
}
|
||||||
const album = availableAlbums[randomIndex];
|
const album = availableAlbums[randomIndex];
|
||||||
|
console.log("🚀 ~ route.tsx:25 ~ GET ~ album:", album);
|
||||||
// Ensure image path starts with a slash
|
// Ensure image path starts with a slash
|
||||||
const imagePath = album.image.startsWith("/") ? album.image : `/${album.image}`;
|
const imagePath = album.image.startsWith("/") ? album.image : `/${album.image}`;
|
||||||
|
console.log("🚀 ~ route.tsx:29 ~ GET ~ imagePath:", imagePath);
|
||||||
// Build absolute URL for the redirect
|
// Build absolute URL for the redirect
|
||||||
const { nextUrl } = request;
|
const { nextUrl } = request;
|
||||||
const absoluteUrl = `${nextUrl.protocol}//${nextUrl.host}${imagePath}`;
|
const absoluteUrl = `${nextUrl.protocol}//${nextUrl.host}${imagePath}`;
|
||||||
|
console.log("🚀 ~ route.tsx:33 ~ GET ~ absoluteUrl:", absoluteUrl);
|
||||||
cookieStore.set("lastImage", album.image);
|
|
||||||
|
|
||||||
return NextResponse.redirect(absoluteUrl, 307);
|
return NextResponse.redirect(absoluteUrl, 307);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue