Files
next-template/src/middleware.ts

35 lines
1.1 KiB
TypeScript

import { type NextRequest, NextResponse } from 'next/server';
import { updateSession } from '@/utils/supabase/middleware';
import { banSuspiciousIPs } from '@/utils/ban-suspicious-ips';
export const middleware = async (request: NextRequest) => {
const banResponse = banSuspiciousIPs(request);
if (banResponse) return banResponse;
const response = await updateSession(request);
const newResponse = NextResponse.next({
request: { headers: new Headers(request.headers) },
});
if (response.headers) {
response.headers.forEach((value, key) => {
newResponse.headers.set(key, value);
});
}
return response;
};
export const config = {
matcher: [
/*
* Match all request paths except:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - /monitoring-tunnel (Sentry monitoring)
* - images - .svg, .png, .jpg, .jpeg, .gif, .webp
* Feel free to modify this pattern to include more paths.
*/
'/((?!_next/static|_next/image|favicon.ico|monitoring-tunnel|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
};