Skip to content

Commit

Permalink
add axios and add url param as well
Browse files Browse the repository at this point in the history
  • Loading branch information
helios2003 committed Jul 22, 2024
1 parent caa3404 commit 3d4063f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 2 additions & 3 deletions apps/studio-next/src/app/api/crawler/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import axios from "axios";
export async function GET(request: NextRequest) {
const Base64searchParams = request.nextUrl.searchParams.get('base64');
const URLsearchParams = request.nextUrl.searchParams.get('url');
console.log(URLsearchParams);

try {
if (!Base64searchParams && !URLsearchParams) return new NextResponse(null, { status: 200 });
let info: DocumentInfo | null = null;
Expand All @@ -20,8 +20,7 @@ export async function GET(request: NextRequest) {
try {
const response = await axios.get(URLsearchParams);
if (response.status === 200) {
console.log(response.data);
info = await parseURL(response.data);
info = response.data;
} else {
return new NextResponse("Not a valid URL", { status: 500 });
}
Expand Down
13 changes: 7 additions & 6 deletions apps/studio-next/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ export async function middleware(request: NextRequest) {
const userAgents = crawlers.map(crawler => crawler.pattern);
const requestInfo = userAgent(request);
const res = NextResponse.next();
for (const ua of userAgents) {
if (requestInfo.ua.toLowerCase().includes(ua.toLowerCase())) {
const documentURL = request.nextUrl.searchParams.get("url");
console.log(documentURL);
// 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 @@ -18,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
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d4063f

Please sign in to comment.