From c29b053bbbd44e578c2f3f5ad07a2ea9dc0ef832 Mon Sep 17 00:00:00 2001 From: david emioma Date: Tue, 2 Apr 2024 18:55:32 +0100 Subject: [PATCH] Debugging Upstash #5 --- app/api/cart/[cartItemId]/route.ts | 8 ++++++-- app/api/cart/route.ts | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/api/cart/[cartItemId]/route.ts b/app/api/cart/[cartItemId]/route.ts index 748c10f..fbec683 100644 --- a/app/api/cart/[cartItemId]/route.ts +++ b/app/api/cart/[cartItemId]/route.ts @@ -131,7 +131,9 @@ export async function PATCH( }, }); - await redis.set(`${user.id}-cart`, newCart); + if (process.env.VERCEL_ENV !== "preview") { + await redis.set(`${user.id}-cart`, newCart); + } return NextResponse.json({ message: "Cart item updated!" }); } catch (err) { @@ -214,7 +216,9 @@ export async function DELETE( }, }); - await redis.set(`${user.id}-cart`, newCart); + if (process.env.VERCEL_ENV !== "preview") { + await redis.set(`${user.id}-cart`, newCart); + } return NextResponse.json({ message: "Cart item deleted!" }); } catch (err) { diff --git a/app/api/cart/route.ts b/app/api/cart/route.ts index 1748c34..6a7146f 100644 --- a/app/api/cart/route.ts +++ b/app/api/cart/route.ts @@ -193,10 +193,12 @@ export async function GET(request: Request) { return NextResponse.json({ cart: null }); } - const cachedCart = await redis.get(`${user.id}-cart`); + if (process.env.VERCEL_ENV !== "preview") { + const cachedCart = await redis.get(`${user.id}-cart`); - if (cachedCart) { - return NextResponse.json(cachedCart); + if (cachedCart) { + return NextResponse.json(cachedCart); + } } const cart = await prismadb.cart.findUnique({ @@ -225,7 +227,9 @@ export async function GET(request: Request) { }, }); - await redis.set(`${user.id}-cart`, cart); + if (process.env.VERCEL_ENV !== "preview") { + await redis.set(`${user.id}-cart`, cart); + } return NextResponse.json(cart); } catch (err) {