first commit

This commit is contained in:
AyrisAI
2026-08-20 01:51:59 +03:00
commit 97b83c7fd4
109 changed files with 21215 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import { NextRequest, NextResponse } from "next/server";
const ROOT_DOMAIN = process.env.ROOT_DOMAIN ?? "menul.io";
// Wildcard subdomain routing: kebapci-ahmet.menul.io -> /menu/kebapci-ahmet
// Custom domains resolve here too once verified (PRD §11).
export function middleware(req: NextRequest) {
const host = req.headers.get("host") ?? "";
const hostname = host.split(":")[0] ?? host;
const isRootDomain = hostname === ROOT_DOMAIN || hostname === `www.${ROOT_DOMAIN}`;
if (isRootDomain || hostname === "localhost") {
return NextResponse.next();
}
const subdomain = hostname.endsWith(`.${ROOT_DOMAIN}`)
? hostname.replace(`.${ROOT_DOMAIN}`, "")
: hostname; // custom domain — resolved to a slug via domains table at render time
const url = req.nextUrl.clone();
url.pathname = `/menu/${subdomain}${req.nextUrl.pathname}`;
return NextResponse.rewrite(url);
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};