| da0f651 | | | 1 | import { NextRequest, NextResponse } from "next/server"; |
| da0f651 | | | 2 | |
| da0f651 | | | 3 | export function middleware(request: NextRequest) { |
| da0f651 | | | 4 | const host = request.headers.get("host") ?? ""; |
| da0f651 | | | 5 | const hostname = host.split(":")[0]; // strip port |
| da0f651 | | | 6 | |
| da0f651 | | | 7 | if (hostname.startsWith("canopy.")) { |
| da0f651 | | | 8 | const url = request.nextUrl.clone(); |
| da0f651 | | | 9 | url.pathname = `/canopy${url.pathname}`; |
| da0f651 | | | 10 | return NextResponse.rewrite(url); |
| da0f651 | | | 11 | } |
| 3cbdca6 | | | 12 | if (hostname.startsWith("ring.")) { |
| 3cbdca6 | | | 13 | const url = request.nextUrl.clone(); |
| 3cbdca6 | | | 14 | url.pathname = `/ring${url.pathname}`; |
| 3cbdca6 | | | 15 | return NextResponse.rewrite(url); |
| 3cbdca6 | | | 16 | } |
| 0b4b582 | | | 17 | if (hostname.startsWith("collab.")) { |
| 0b4b582 | | | 18 | const url = request.nextUrl.clone(); |
| 0b4b582 | | | 19 | url.pathname = `/collab${url.pathname}`; |
| 0b4b582 | | | 20 | return NextResponse.rewrite(url); |
| 0b4b582 | | | 21 | } |
| da0f651 | | | 22 | return NextResponse.next(); |
| da0f651 | | | 23 | } |
| da0f651 | | | 24 | |
| da0f651 | | | 25 | export const config = { |
| da0f651 | | | 26 | matcher: [ |
| da0f651 | | | 27 | // Match all paths except Next.js internals and static files |
| 0b4b582 | | | 28 | "/((?!_next/static|_next/image|favicon\\.svg|canopy-favicon\\.svg|ring-favicon\\.svg|collab-favicon\\.svg|api/).*)", |
| da0f651 | | | 29 | ], |
| da0f651 | | | 30 | }; |