INNER CODE UNIT · TypeScript

getRateLimitSession

Ammaar-Alam/minebench · middleware.ts:234

function getRateLimitSession(req: NextRequest, fallbackBucketId: string) {
  const existing = req.cookies.get(RATE_LIMIT_SESSION_COOKIE)?.value?.trim();
  if (existing) return { bucketId: existing, cookieValue: null, isNew: false };
  const id = crypto.randomUUID();
  return {
    // fallback catches clients that drop the cookie
    bucketId: fallbackBucketId,
    cookieValue: id,
    isNew: true,
  };
}

export async function middleware(req: NextRequest) {
  const canonicalRedirect = maybeRedirectToCanonicalHost(req);
  if (canonicalRedirect) return canonicalRedirect;

  const modelSlugRedirect = maybeRedirectToCanonicalModelSlug(req);
  if (modelSlugRedirect) return modelSlugRedirect;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…