From c7b64379bfdd691e772e827d38334f7fab2443dd Mon Sep 17 00:00:00 2001 From: Andrey Avtomonov Date: Fri, 15 May 2026 02:30:20 +0200 Subject: [PATCH] docs-site: serve under /ktx and redirect ktx.sh to docs.kaelio.com - Add Next.js basePath '/ktx' so the docs site mounts under /ktx, enabling it to be reverse-proxied by docs.kaelio.com. - Add host-based redirects so docs.ktx.sh and ktx.sh permanently redirect to https://docs.kaelio.com/ktx, making docs.kaelio.com the single canonical home for KTX docs. - Update markdown-preference middleware to be basePath-aware so the llms.mdx rewrite still fires on /ktx/docs/* requests. --- docs-site/middleware.ts | 5 +++-- docs-site/next.config.mjs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs-site/middleware.ts b/docs-site/middleware.ts index 670ebd33..1b892076 100644 --- a/docs-site/middleware.ts +++ b/docs-site/middleware.ts @@ -12,12 +12,13 @@ export function middleware(request: NextRequest) { } const { pathname } = request.nextUrl; - if (!pathname.startsWith("/docs/") || pathname.endsWith(".md")) { + const docsIndex = pathname.indexOf("/docs/"); + if (docsIndex < 0 || pathname.endsWith(".md")) { return NextResponse.next(); } const rewriteUrl = request.nextUrl.clone(); - rewriteUrl.pathname = `/llms.mdx${pathname}`; + rewriteUrl.pathname = `${pathname.slice(0, docsIndex)}/llms.mdx${pathname.slice(docsIndex)}`; return NextResponse.rewrite(rewriteUrl); } diff --git a/docs-site/next.config.mjs b/docs-site/next.config.mjs index 8b28486f..a348acd0 100644 --- a/docs-site/next.config.mjs +++ b/docs-site/next.config.mjs @@ -4,6 +4,7 @@ const withMDX = createMDX(); /** @type {import('next').NextConfig} */ const config = { + basePath: "/ktx", async rewrites() { return [ { @@ -12,6 +13,24 @@ const config = { }, ]; }, + async redirects() { + return [ + { + source: "/:path*", + has: [{ type: "host", value: "docs.ktx.sh" }], + destination: "https://docs.kaelio.com/ktx/:path*", + permanent: true, + basePath: false, + }, + { + source: "/:path*", + has: [{ type: "host", value: "ktx.sh" }], + destination: "https://docs.kaelio.com/ktx/:path*", + permanent: true, + basePath: false, + }, + ]; + }, }; export default withMDX(config);