diff --git a/src/middleware.ts b/src/middleware.ts index 7c97112..39a81af 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -2,18 +2,20 @@ import type { NextRequest } from "next/server" import { NextResponse } from "next/server" +import { siteUrl } from "./utils/seo" + export const config = { matcher: ["/((?!api/|_next/|_static/|_vercel|[\\w-]+\\.\\w+).*)"], } export function middleware(req: NextRequest) { + const currentUrl = siteUrl().replace(/^https:\/\//, "") + console.log("currentUrl", currentUrl) const baseUrl = "kevinwolf.cr" - - const docsProject = - req.headers - .get("host")! - .replace(`localhost:${process.env.PORT}`, baseUrl) - .replace(new RegExp(`^(?:([^.]+)\\.)?${baseUrl.replace(/\./g, "\\.")}$`), "$1") || "" + const url = req.headers.get("host")!.replace(currentUrl, baseUrl) + console.log("url", url) + const docsProject = url.replace(new RegExp(`^(?:([^.]+)\\.)?${baseUrl.replace(/\./g, "\\.")}$`), "$1") || "" + console.log("docsProject", docsProject) if (docsProject) return NextResponse.rewrite(new URL(`/docs/${docsProject}${req.nextUrl.pathname}`, req.url)) }