import { NextResponse, type NextRequest } from 'next/server';
import { EnvRedirectRepository } from '@/lib/seo/redirects';

const redirects = new EnvRedirectRepository();

export function proxy(request: NextRequest) {
  const redirect = redirects.findBySourcePath(request.nextUrl.pathname);
  if (!redirect) return NextResponse.next();

  return NextResponse.redirect(new URL(redirect.to, request.url), 301);
}

export const config = {
  matcher: ['/((?!api/revalidate|_next/static|_next/image|favicon.ico).*)'],
};
