2025-06-22 14:26:03 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import type { NextRequest } from "next/server";
|
2025-07-15 13:29:16 +07:00
|
|
|
import { env } from "./env";
|
2025-06-22 14:26:03 +02:00
|
|
|
|
2025-06-22 14:41:08 +02:00
|
|
|
export async function middleware(request: NextRequest) {
|
2025-07-16 22:47:17 +02:00
|
|
|
const protectedPaths = ["/editor", "/projects"];
|
|
|
|
|
|
2025-07-09 07:49:17 +02:00
|
|
|
// Handle fuckcapcut.com domain redirect
|
|
|
|
|
if (request.headers.get("host") === "fuckcapcut.com") {
|
|
|
|
|
return NextResponse.redirect("https://opencut.app/why-not-capcut", 301);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-22 14:41:08 +02:00
|
|
|
const path = request.nextUrl.pathname;
|
|
|
|
|
|
2025-07-16 22:47:17 +02:00
|
|
|
if (protectedPaths.includes(path) && env.NODE_ENV === "production") {
|
2025-06-30 19:58:36 +02:00
|
|
|
const homeUrl = new URL("/", request.url);
|
|
|
|
|
homeUrl.searchParams.set("redirect", request.url);
|
|
|
|
|
return NextResponse.redirect(homeUrl);
|
2025-06-22 14:26:03 +02:00
|
|
|
}
|
2025-06-22 14:41:08 +02:00
|
|
|
|
|
|
|
|
return NextResponse.next();
|
2025-06-22 14:26:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const config = {
|
2025-06-22 14:41:08 +02:00
|
|
|
matcher: [
|
|
|
|
|
/*
|
|
|
|
|
* Match all request paths except for the ones starting with:
|
|
|
|
|
* - api (API routes)
|
|
|
|
|
* - _next/static (static files)
|
|
|
|
|
* - _next/image (image optimization files)
|
|
|
|
|
* - favicon.ico (favicon file)
|
|
|
|
|
*/
|
|
|
|
|
"/((?!api|_next/static|_next/image|favicon.ico).*)",
|
|
|
|
|
],
|
2025-06-22 14:26:03 +02:00
|
|
|
};
|