Skip to content

Commit

Permalink
fix: not return cache if limited
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 5, 2023
1 parent 95a6504 commit 3695bf8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const redis = Redis.fromEnv();

export async function middleware(req: NextRequest, context: NextFetchEvent) {
const { apiKey, bvId } = await req.json();
const result = await redis.get<string>(bvId);
if (!isDev && result) {
console.log("hit cache for ", bvId);
return NextResponse.json(result);
}

// licenseKeys
if (apiKey) {
Expand All @@ -34,6 +29,12 @@ export async function middleware(req: NextRequest, context: NextFetchEvent) {
if (!apiKey && !success) {
return NextResponse.redirect(new URL("/shop", req.url));
}

const result = await redis.get<string>(bvId);
if (!isDev && result) {
console.log("hit cache for ", bvId);
return NextResponse.json(result);
}
}

export const config = {
Expand Down

1 comment on commit 3695bf8

@vercel
Copy link

@vercel vercel bot commented on 3695bf8 Mar 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.