fix(frontend): middleware rewrites remote actor URLs to avoid Next.js file-extension routing issue
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
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
This commit is contained in:
23
thoughts-frontend/middleware.ts
Normal file
23
thoughts-frontend/middleware.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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*",
|
||||
};
|
||||
Reference in New Issue
Block a user