Files

26 lines
625 B
TypeScript
Raw Permalink Normal View History

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
/**
* Experimental site: only `/` exists. Send any other page request home
* so users never see a 404 screen.
*/
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
if (
pathname === "/" ||
pathname.startsWith("/_next") ||
pathname.startsWith("/api") ||
pathname.includes(".")
) {
return NextResponse.next();
}
return NextResponse.redirect(new URL("/", request.url));
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};