File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import { NextResponse } from 'next/server'
2+ import type { NextRequest } from 'next/server'
3+ import { SINGLE_TENANT_ORG_DOMAIN } from '@/lib/constants'
4+
5+ export async function proxy ( request : NextRequest ) {
6+ const url = request . nextUrl . clone ( ) ;
7+
8+ if (
9+ url . pathname . startsWith ( '/login' ) ||
10+ url . pathname . startsWith ( '/redeem' ) ||
11+ url . pathname . startsWith ( '/signup' ) ||
12+ url . pathname . startsWith ( '/invite' ) ||
13+ url . pathname . startsWith ( '/onboard' ) ||
14+ url . pathname . startsWith ( '/oauth' )
15+ ) {
16+ return NextResponse . next ( ) ;
17+ }
18+
19+ const pathSegments = url . pathname . split ( '/' ) . filter ( Boolean ) ;
20+ const currentDomain = pathSegments [ 0 ] ;
21+
22+ // If we're already on the correct domain path, allow
23+ if ( currentDomain === SINGLE_TENANT_ORG_DOMAIN ) {
24+ return NextResponse . next ( ) ;
25+ }
26+
27+ url . pathname = `/${ SINGLE_TENANT_ORG_DOMAIN } ${ pathSegments . length > 1 ? '/' + pathSegments . slice ( 1 ) . join ( '/' ) : '' } ` ;
28+ return NextResponse . redirect ( url ) ;
29+ }
30+
31+ export const config = {
32+ // https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
33+ matcher : [
34+ '/((?!api|_next/static|.well-known/oauth-authorization-server|.well-known/oauth-protected-resource|ingest|_next/image|favicon.ico|sitemap.xml|robots.txt|manifest.json|logo_192.png|logo_512.png|sb_logo_light_large.png|arrow.png|placeholder_avatar.png|sb_logo_dark_small.png|sb_logo_light_small.png).*)' ,
35+ ] ,
36+ }
You can’t perform that action at this time.
0 commit comments