Include hub Next API routes and admin module select so the China-only Hub ship can build and mount on nomadro.com. Co-authored-by: Cursor <cursoragent@cursor.com>
128 lines
3.4 KiB
TypeScript
128 lines
3.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
||
import type { NextRequest } from "next/server";
|
||
|
||
/**
|
||
* Compat redirects for vertical apps mounted under path prefixes.
|
||
* Old standalone URLs → portal mounts.
|
||
*/
|
||
const COMMUNITY_ROOTS = new Set([
|
||
"about",
|
||
"ai",
|
||
"blog",
|
||
"careers",
|
||
"changelog",
|
||
"chat",
|
||
"compare",
|
||
"contact",
|
||
"cookies",
|
||
"dating",
|
||
"destinations",
|
||
"digital",
|
||
"feedback",
|
||
"gigs",
|
||
"guidelines",
|
||
"help",
|
||
"join",
|
||
"login",
|
||
"map",
|
||
"meetups",
|
||
"members",
|
||
"next-stop",
|
||
"notifications",
|
||
"plan",
|
||
"press",
|
||
"pricing",
|
||
"privacy",
|
||
"profile",
|
||
"report",
|
||
"safety",
|
||
"services",
|
||
"settings",
|
||
"submit",
|
||
"support",
|
||
"terms",
|
||
"tools",
|
||
"videos",
|
||
]);
|
||
|
||
/** Standalone nomadvip paths → /vip/* (do not steal /book) */
|
||
const VIP_ROOTS = new Set(["topic", "paid", "cloudphone"]);
|
||
|
||
export function proxy(request: NextRequest) {
|
||
const { pathname, search } = request.nextUrl;
|
||
|
||
if (pathname === '/notifications' || pathname.startsWith('/notifications/')) {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = `/social${pathname}`;
|
||
return NextResponse.redirect(url, 308);
|
||
}
|
||
|
||
// 旧版曾 308 /social→/(会被浏览器永久缓存)。现改为临时 302 到 /social/home,
|
||
// 门户与社群内链一律走 /social/home,避开中毒缓存。
|
||
if (pathname === "/social" || pathname === "/social/") {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = "/social/home";
|
||
url.search = search;
|
||
return NextResponse.redirect(url, 302);
|
||
}
|
||
|
||
// Independent hub fork (copy of social) — bare /hub → /hub/home
|
||
if (pathname === "/hub" || pathname === "/hub/") {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = "/hub/home";
|
||
url.search = search;
|
||
return NextResponse.redirect(url, 302);
|
||
}
|
||
|
||
// Alias: /ebook → /book (product mount path)
|
||
if (pathname === "/ebook" || pathname.startsWith("/ebook/")) {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = pathname.replace(/^\/ebook(?=\/|$)/, "/book");
|
||
return NextResponse.redirect(url, 308);
|
||
}
|
||
|
||
// /read and /read/* already handled by app/read routes.
|
||
// Extra: bare community routes that used to live at site root.
|
||
const seg = pathname.split("/").filter(Boolean)[0];
|
||
if (
|
||
seg &&
|
||
VIP_ROOTS.has(seg) &&
|
||
!pathname.startsWith("/vip/")
|
||
) {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = `/vip${pathname}`;
|
||
return NextResponse.redirect(url, 308);
|
||
}
|
||
if (
|
||
seg &&
|
||
COMMUNITY_ROOTS.has(seg) &&
|
||
!pathname.startsWith("/community/") &&
|
||
pathname !== "/community"
|
||
) {
|
||
const url = request.nextUrl.clone();
|
||
url.pathname = `/community${pathname}`;
|
||
return NextResponse.redirect(url, 308);
|
||
}
|
||
|
||
// Fix login?next=/foo → next=/community/foo when missing prefix
|
||
if (pathname === "/community/login" || pathname === "/login") {
|
||
const next = request.nextUrl.searchParams.get("next");
|
||
if (next && next.startsWith("/") && !next.startsWith("/community") && !next.startsWith("/book") && !next.startsWith("/nav") && !next.startsWith("/vip") && !next.startsWith("/http")) {
|
||
const url = request.nextUrl.clone();
|
||
if (pathname === "/login") {
|
||
url.pathname = "/community/login";
|
||
}
|
||
url.searchParams.set("next", `/community${next === "/" ? "" : next}`);
|
||
return NextResponse.redirect(url, 308);
|
||
}
|
||
}
|
||
|
||
return NextResponse.next();
|
||
}
|
||
|
||
export const config = {
|
||
matcher: [
|
||
"/((?!_next/static|_next/image|favicon.ico|icons/|api/|.*\\..*).*)",
|
||
],
|
||
};
|