Jotley / website / src / middleware.ts
| 1 | import { NextResponse } from 'next/server'; |
| 2 | import type { NextRequest } from 'next/server'; |
| 3 | |
| 4 | export function middleware(request: NextRequest) { |
| 5 | const { pathname } = request.nextUrl; |
| 6 | if (pathname === '/tos' || pathname === '/terms') { |
| 7 | const destination = request.nextUrl.clone(); |
| 8 | destination.pathname = '/app-notices'; |
| 9 | return NextResponse.redirect(destination, 308); |
| 10 | } |
| 11 | |
| 12 | const allowedPaths = [ |
| 13 | '/_next', |
| 14 | '/api', |
| 15 | '/favicon', |
| 16 | '/jotley-icon', |
| 17 | '/privacy', |
| 18 | '/app-notices', |
| 19 | '/download', |
| 20 | '/appcast.xml', |
| 21 | '/Jotley-', |
| 22 | '/install-step-', |
| 23 | '/mac-release.json', |
| 24 | '/maintenance', |
| 25 | '/robots.txt', |
| 26 | '/sitemap.xml', |
| 27 | '/llms.txt', |
| 28 | ]; |
| 29 | |
| 30 | const isAllowed = allowedPaths.some(path => pathname.startsWith(path)); |
| 31 | |
| 32 | if (process.env.NEXT_PUBLIC_MAINTENANCE_MODE === 'true' && !isAllowed) { |
| 33 | // Signal temporary downtime rather than indexing the maintenance copy. |
| 34 | return NextResponse.rewrite(new URL('/maintenance', request.url), { |
| 35 | status: 503, |
| 36 | headers: { 'Retry-After': '3600' }, |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | return NextResponse.next(); |
| 41 | } |
| 42 | |
| 43 | export const config = { |
| 44 | matcher: [ |
| 45 | /* |
| 46 | * Match all request paths except: |
| 47 | * - _next/static (static files) |
| 48 | * - _next/image (image optimization files) |
| 49 | * - favicon.ico (favicon file) |
| 50 | * - public folder files |
| 51 | */ |
| 52 | '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4)$).*)', |
| 53 | ], |
| 54 | }; |