chore: early return for next.js static assets (#19678)
This commit is contained in:
@@ -39,10 +39,21 @@ export function checkPostMethod(req: NextRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function checkStaticFiles(pathname: string) {
|
||||
const hasFileExtension = /\.(svg|png|jpg|jpeg|gif|webp|ico)$/.test(pathname);
|
||||
// Skip Next.js internal paths (_next) and static assets
|
||||
if (pathname.startsWith("/_next") || hasFileExtension) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
}
|
||||
|
||||
const middleware = async (req: NextRequest): Promise<NextResponse<unknown>> => {
|
||||
const postCheckResult = checkPostMethod(req);
|
||||
if (postCheckResult) return postCheckResult;
|
||||
|
||||
const isStaticFile = checkStaticFiles(req.nextUrl.pathname);
|
||||
if (isStaticFile) return isStaticFile;
|
||||
|
||||
const url = req.nextUrl;
|
||||
const requestHeaders = new Headers(req.headers);
|
||||
requestHeaders.set("x-url", req.url);
|
||||
|
||||
Reference in New Issue
Block a user