import { NextResponse } from 'next/server'; import type { NextRequest } from 'next/server'; export function middleware(request: NextRequest) { const { pathname } = request.nextUrl; if (pathname === '/tos' || pathname === '/terms') { const destination = request.nextUrl.clone(); destination.pathname = '/app-notices'; return NextResponse.redirect(destination, 308); } const allowedPaths = [ '/_next', '/api', '/favicon', '/jotley-icon', '/privacy', '/app-notices', '/download', '/appcast.xml', '/Jotley-', '/install-step-', '/mac-release.json', '/maintenance', '/robots.txt', '/sitemap.xml', '/llms.txt', ]; const isAllowed = allowedPaths.some(path => pathname.startsWith(path)); if (process.env.NEXT_PUBLIC_MAINTENANCE_MODE === 'true' && !isAllowed) { // Signal temporary downtime rather than indexing the maintenance copy. return NextResponse.rewrite(new URL('/maintenance', request.url), { status: 503, headers: { 'Retry-After': '3600' }, }); } return NextResponse.next(); } export const config = { matcher: [ /* * Match all request paths except: * - _next/static (static files) * - _next/image (image optimization files) * - favicon.ico (favicon file) * - public folder files */ '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4)$).*)', ], };