Skip to content

Commit

Permalink
better handling of invalid doc
Browse files Browse the repository at this point in the history
  • Loading branch information
helios2003 committed Jul 9, 2024
1 parent 8ba36ee commit 786f083
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 22 additions & 2 deletions apps/studio-next/src/app/api/crawler/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import parseURL from "@/helpers/parser";
import { DocumentInfo } from "@/types";
import ogImage from '@/img/meta-studio-og-image.jpeg';

export async function GET(request: NextRequest) {
try {
Expand All @@ -9,8 +10,27 @@ export async function GET(request: NextRequest) {

const info: DocumentInfo | null = await parseURL(searchParams);

if (!info) return new NextResponse(null, { status: 200 });

if (!info) {
const crawlerInfo = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>"AsyncAPI Studio"</title>
<meta property="og:title" content="AsyncAPI Studio" />
<meta property="og:description" content="Studio for AsyncAPI specification, where you can validate, view preview documentation, and generate templates from AsyncAPI document." />
<meta property="og:url" content="https://studio-next.netlify.app" />
<meta property="og:image" content=${ogImage} />
`
return new NextResponse(crawlerInfo, {
headers: {
'Content-Type': 'text/html',
},
})
}

let ogImageParams = new URLSearchParams();

if (info.title !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

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

0 comments on commit 786f083

Please sign in to comment.