-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmiddleware.ts
More file actions
23 lines (19 loc) · 977 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
23 lines (19 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { gate } from "@/lib/crawl-gateway";
import { screenSubmission } from "@/lib/submission-guard";
import { NextResponse, type NextRequest } from "next/server";
import { trackReferralCode } from "@profullstack/stack/referrals";
export async function middleware(request: NextRequest) {
// Crawl gateway first: AI training crawlers get 402 Payment Required (or the
// sales page at /crawl) unless they present a paid pass. People, Googlebot
// and retrieval crawlers fall through to everything below.
// A submission campaign is refused (403) before the daily cap, so the
// address is banned rather than offered a pass.
const refused = await screenSubmission(request);
if (refused) return refused;
const answer = await gate(request);
if (answer) return answer;
return trackReferralCode(request, NextResponse.next() as any);
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\.(?:svg|png|jpg|jpeg|gif|webp)$).*)"],
};