From e748e2a648868e9f454482f9d30fb020f547a3f3 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 1 Aug 2023 11:14:45 +0100 Subject: [PATCH] feat: redirection --- next.config.js | 25 ++++++++++++++++++++++++ src/app/site/[site]/sitemap.xml/route.ts | 1 + src/middleware.ts | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/next.config.js b/next.config.js index d96876c8..e8396667 100644 --- a/next.config.js +++ b/next.config.js @@ -128,6 +128,31 @@ module.exports = withSentryConfig( ] }, staticPageGenerationTimeout: 3600, + + async redirects() { + return [ + { + source: "/sitemap.txt", + destination: "/sitemap.xml", + permanent: true, + }, + { + source: "/sitemap.xml.gz", + destination: "/sitemap.xml", + permanent: true, + }, + { + source: "/sitemap_index.xml", + destination: "/sitemap.xml", + permanent: true, + }, + { + source: "/sitemaps.xml", + destination: "/sitemap.xml", + permanent: true, + }, + ] + }, }), ), { diff --git a/src/app/site/[site]/sitemap.xml/route.ts b/src/app/site/[site]/sitemap.xml/route.ts index 7b94e94e..82fe4814 100644 --- a/src/app/site/[site]/sitemap.xml/route.ts +++ b/src/app/site/[site]/sitemap.xml/route.ts @@ -37,6 +37,7 @@ export const GET = async (req: NextRequest) => { type: "post", visibility: PageVisibilityEnum.Published, limit: 1000, + skipExpansion: true, }, queryClient, ) diff --git a/src/middleware.ts b/src/middleware.ts index 863e244d..e509e62e 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -44,7 +44,7 @@ export default async function middleware(req: NextRequest) { return NextResponse.redirect(`https://${req.headers.get("host")}/feed`, 301) } - console.debug(`${req.method} ${req.nextUrl.pathname}${req.nextUrl.search}`) + console.debug(`${req.method} ${req.nextUrl}`) if ( pathname.startsWith("/api/") || @@ -54,7 +54,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 === "/monitoring" || + pathname === "favicon.ico" ) { return NextResponse.next() }