sourcebot/packages/web/src/middleware.ts
Brendan Kellam bbf8b9be86
Magic links (#199)
* wip on magic link support

* Switch to nodemailer / resend for transactional mail

* Further cleanup

* Add stylized email using react-email

* fix
2025-02-18 11:34:07 -08:00

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).*)'
],
}