From 778d685cb0905aa0fc0e0060f11cc3be30532fe2 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 8 May 2023 17:48:04 +0100 Subject: [PATCH] feat: robots.txt app router --- src/app/feed/hottest/{route.tsx => route.ts} | 0 src/app/feed/latest/{route.tsx => route.ts} | 0 src/app/robots.ts | 11 +++++++++++ src/middleware.ts | 4 +++- 4 files changed, 14 insertions(+), 1 deletion(-) rename src/app/feed/hottest/{route.tsx => route.ts} (100%) rename src/app/feed/latest/{route.tsx => route.ts} (100%) create mode 100644 src/app/robots.ts diff --git a/src/app/feed/hottest/route.tsx b/src/app/feed/hottest/route.ts similarity index 100% rename from src/app/feed/hottest/route.tsx rename to src/app/feed/hottest/route.ts diff --git a/src/app/feed/latest/route.tsx b/src/app/feed/latest/route.ts similarity index 100% rename from src/app/feed/latest/route.tsx rename to src/app/feed/latest/route.ts diff --git a/src/app/robots.ts b/src/app/robots.ts new file mode 100644 index 00000000..5a741fd4 --- /dev/null +++ b/src/app/robots.ts @@ -0,0 +1,11 @@ +import { MetadataRoute } from "next" + +export default function robots(): MetadataRoute.Robots { + return { + rules: { + userAgent: "*", + allow: "/", + disallow: ["/dashboard/", "/preview/", "/api/"], + }, + } +} diff --git a/src/middleware.ts b/src/middleware.ts index ea12dd5a..efc06eec 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -53,7 +53,9 @@ export default async function middleware(req: NextRequest) { pathname.startsWith("/locales/") || pathname.match(/^\/(workbox|worker|fallback)-\w+\.js(\.map)?$/) || pathname === "/sw.js" || - pathname === "/sw.js.map" + pathname === "/sw.js.map" || + pathname === "/robots.txt" || + pathname === "/sitemap.xml" ) { return NextResponse.next() }