diff --git a/app/[id]/page.tsx b/app/[id]/page.tsx index 01efc52..c18d115 100644 --- a/app/[id]/page.tsx +++ b/app/[id]/page.tsx @@ -1,4 +1,5 @@ import { headers } from 'next/headers' +import { notFound } from 'next/navigation' import { SiteFrame } from '@/components/site/SiteFrame' import { PasteView } from '@/components/PasteView' import { PasswordPrompt } from '@/components/PasswordPrompt' @@ -25,14 +26,11 @@ interface PageProps { export default async function PastePage({ params }: PageProps) { const { id } = await params + // An unknown ID answers 404 through app/not-found.tsx, which shows the same + // panel. Rendering the panel here answered 200, so /robots.txt and every + // mistyped link looked like a real page ("Paste robots.txt") to a crawler. const row = await getPasteRow(id) - if (!row) { - return ( - - - - ) - } + if (!row) notFound() if (isPasteExpired(row)) { return ( diff --git a/app/robots.ts b/app/robots.ts new file mode 100644 index 0000000..a5e3980 --- /dev/null +++ b/app/robots.ts @@ -0,0 +1,12 @@ +import type { MetadataRoute } from 'next' + +/** + * robots.txt. Without this file `/robots.txt` fell through to the `[id]` + * route and came back as a paste page. Raw text and downloads are the same + * content as the paste page in another form, and the API is not for crawlers. + */ +export default function robots(): MetadataRoute.Robots { + return { + rules: [{ userAgent: '*', allow: '/', disallow: ['/api/', '/raw/', '/dl/'] }], + } +}