Skip to content

Commit

Permalink
use user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
helios2003 committed Jul 22, 2024
1 parent 3d4063f commit bddad2a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions apps/studio-next/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export async function middleware(request: NextRequest) {
const userAgents = crawlers.map(crawler => crawler.pattern);
const requestInfo = userAgent(request);
const res = NextResponse.next();
const documentURL = request.nextUrl.searchParams.get("url");
console.log(documentURL);
// for (const ua of userAgents) {
// if (requestInfo.ua.toLowerCase().includes(ua.toLowerCase())) {

for (const ua of userAgents) {
if (requestInfo.ua.toLowerCase().includes(ua.toLowerCase())) {
const encodedDocument = request.nextUrl.searchParams.get("base64");
const documentURL = request.nextUrl.searchParams.get("url");
if (!encodedDocument && !documentURL) {
return res;
}
Expand All @@ -19,10 +19,10 @@ export async function middleware(request: NextRequest) {
if (documentURL) {
return NextResponse.rewrite(new URL(`/api/crawler?url=${documentURL}`, request.url));
}
return res;
}
//}
//}
}
return res;
}

export const config = {
matcher: ['/:base64', '/:url'],
Expand Down

0 comments on commit bddad2a

Please sign in to comment.