mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-14 21:35:25 +00:00
* wip on magic link support * Switch to nodemailer / resend for transactional mail * Further cleanup * Add stylized email using react-email * fix
34 lines
No EOL
999 B
TypeScript
34 lines
No EOL
999 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
const host = request.headers.get("host")!;
|
|
|
|
const searchParams = request.nextUrl.searchParams.toString();
|
|
const path = `${request.nextUrl.pathname}${
|
|
searchParams.length > 0 ? `?${searchParams}` : ""
|
|
}`;
|
|
|
|
if (
|
|
host === process.env.NEXT_PUBLIC_ROOT_DOMAIN ||
|
|
host === 'localhost:3000'
|
|
) {
|
|
return NextResponse.next();
|
|
}
|
|
|
|
const subdomain = host.split(".")[0];
|
|
return NextResponse.rewrite(new URL(`/${subdomain}${path}`, request.url));
|
|
};
|
|
|
|
|
|
export const config = {
|
|
// https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
|
|
matcher: [
|
|
/**
|
|
* Match all paths except for:
|
|
* 1. /api routes
|
|
* 2. _next/ routes
|
|
* 3. ingest (PostHog route)
|
|
*/
|
|
'/((?!api|_next/static|ingest|_next/image|favicon.ico|sitemap.xml|robots.txt).*)'
|
|
],
|
|
} |