Files
discord.js/apps/guide/src/middleware.ts
Naiyar 68835b3ff7 refactor(guide): redirect old urls to /legacy (#11170)
* refactor(guide): redirect old urls to /legacy

* chore: suggestion

Co-authored-by: Almeida <github@almeidx.dev>

---------

Co-authored-by: Almeida <github@almeidx.dev>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
2025-10-20 13:13:36 +00:00

24 lines
735 B
TypeScript

import { NextResponse, type NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
// TODO: Remove this eventually
if (request.nextUrl.pathname.startsWith('/guide/')) {
const newUrl = request.nextUrl.clone();
newUrl.pathname = newUrl.pathname.replace('/guide/', '/');
return NextResponse.redirect(newUrl);
}
// Redirect old urls to /legacy
if (!request.nextUrl.pathname.startsWith('/legacy') && !request.nextUrl.pathname.startsWith('/voice')) {
const newUrl = request.nextUrl.clone();
newUrl.pathname = `/legacy${newUrl.pathname}`;
return NextResponse.redirect(newUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ['/((?!_next|api|og|.*\\..*|_static).*)'],
};