middleware remove logs
This commit is contained in:
@@ -13,15 +13,11 @@ export function middleware(req: NextRequest) {
|
|||||||
const host = req.headers.get("host") || "";
|
const host = req.headers.get("host") || "";
|
||||||
const tenantPath = HOST_MAP[host.toLowerCase()] || "";
|
const tenantPath = HOST_MAP[host.toLowerCase()] || "";
|
||||||
|
|
||||||
console.log("[middleware] host:", host, "| tenantPath:", tenantPath || "(none)");
|
|
||||||
|
|
||||||
if (!tenantPath) {
|
if (!tenantPath) {
|
||||||
console.log("[middleware] → next() (no tenant for host)");
|
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathname = req.nextUrl.pathname;
|
const pathname = req.nextUrl.pathname;
|
||||||
console.log("[middleware] pathname:", pathname);
|
|
||||||
|
|
||||||
// مسیرهای api و استاتیک را rewrite نکن
|
// مسیرهای api و استاتیک را rewrite نکن
|
||||||
if (
|
if (
|
||||||
@@ -29,7 +25,6 @@ export function middleware(req: NextRequest) {
|
|||||||
pathname.startsWith("/_next") ||
|
pathname.startsWith("/_next") ||
|
||||||
pathname.includes(".")
|
pathname.includes(".")
|
||||||
) {
|
) {
|
||||||
console.log("[middleware] → next() (api/static path)");
|
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,19 +32,16 @@ export function middleware(req: NextRequest) {
|
|||||||
if (pathname === "/") {
|
if (pathname === "/") {
|
||||||
const url = req.nextUrl.clone();
|
const url = req.nextUrl.clone();
|
||||||
url.pathname = tenantPath;
|
url.pathname = tenantPath;
|
||||||
console.log("[middleware] → redirect to:", url.pathname);
|
|
||||||
return NextResponse.redirect(url);
|
return NextResponse.redirect(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// اگر مسیر از قبل با tenant یکی است (مثلاً /passata یا /passata/menu)، rewrite نکن
|
// اگر مسیر از قبل با tenant یکی است (مثلاً /passata یا /passata/menu)، rewrite نکن
|
||||||
if (pathname === tenantPath || pathname.startsWith(tenantPath + "/")) {
|
if (pathname === tenantPath || pathname.startsWith(tenantPath + "/")) {
|
||||||
console.log("[middleware] → next() (path already has tenant)");
|
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = req.nextUrl.clone();
|
const url = req.nextUrl.clone();
|
||||||
url.pathname = `${tenantPath}${pathname}`;
|
url.pathname = `${tenantPath}${pathname}`;
|
||||||
console.log("[middleware] → rewrite to:", url.pathname);
|
|
||||||
return NextResponse.rewrite(url);
|
return NextResponse.rewrite(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user