Files
thoughts/thoughts-frontend/middleware.ts
Gabriel Kaszewski 072d06cb46
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 31s
test / unit (pull_request) Failing after 11m18s
test / integration (pull_request) Failing after 18m1s
fix(frontend): middleware rewrites remote actor URLs to avoid Next.js file-extension routing issue
2026-05-14 22:40:21 +02:00

24 lines
692 B
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const parts = request.nextUrl.pathname.split("/");
// /users/@user@instance or /users/%40user%40instance
if (parts.length === 3 && parts[1] === "users") {
const decoded = decodeURIComponent(parts[2]);
if (decoded.startsWith("@") && decoded.indexOf("@", 1) !== -1) {
const url = request.nextUrl.clone();
url.pathname = "/remote-actor";
url.searchParams.set("handle", decoded);
return NextResponse.rewrite(url);
}
}
return NextResponse.next();
}
export const config = {
matcher: "/users/:path*",
};