Skip to content

Commit 85fb876

Browse files
committed
reverted changes to middleware
1 parent 2595726 commit 85fb876

1 file changed

Lines changed: 6 additions & 44 deletions

File tree

apps/sim/middleware.ts

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,16 @@ export async function middleware(request: NextRequest) {
2727
const url = request.nextUrl
2828
const hostname = request.headers.get('host') || ''
2929

30-
let isCustomDomain = false
31-
let subdomain: string | null = null
32-
33-
try {
34-
const baseDomainUrl = new URL(`${request.nextUrl.protocol}//${BASE_DOMAIN}`)
35-
const baseDomainHost = baseDomainUrl.hostname
36-
const baseDomainPort = baseDomainUrl.port
37-
38-
if (hostname !== BASE_DOMAIN && !hostname.startsWith('www.')) {
39-
if (isDevelopment && baseDomainHost === 'localhost') {
40-
const hostnameParts = hostname.split('.')
41-
if (hostnameParts.length >= 2 && hostnameParts[1] === 'localhost') {
42-
const lastPart = hostnameParts[hostnameParts.length - 1]
43-
const hasPort = lastPart.includes(':')
44-
const port = hasPort ? lastPart.split(':')[1] : null
45-
46-
if (!baseDomainPort && !hasPort) {
47-
// Both have no port - valid
48-
isCustomDomain = true
49-
subdomain = hostnameParts[0]
50-
} else if (baseDomainPort && hasPort && port === baseDomainPort) {
51-
// Both have matching ports - valid
52-
isCustomDomain = true
53-
subdomain = hostnameParts[0]
54-
}
55-
}
56-
} else if (!isDevelopment && hostname.endsWith('.simstudio.ai')) {
57-
const hostnameParts = hostname.split('.')
58-
if (hostnameParts.length >= 3) {
59-
isCustomDomain = true
60-
subdomain = hostnameParts[0]
61-
}
62-
}
63-
}
64-
} catch (error) {
65-
logger.warn('Error parsing base domain for subdomain detection:', error)
66-
isCustomDomain =
67-
hostname !== BASE_DOMAIN &&
68-
!hostname.startsWith('www.') &&
69-
hostname.includes(isDevelopment ? 'localhost' : 'simstudio.ai')
70-
subdomain = isCustomDomain ? hostname.split('.')[0] : null
71-
}
30+
// Extract subdomain
31+
const isCustomDomain =
32+
hostname !== BASE_DOMAIN &&
33+
!hostname.startsWith('www.') &&
34+
hostname.includes(isDevelopment ? 'localhost' : 'simstudio.ai')
35+
const subdomain = isCustomDomain ? hostname.split('.')[0] : null
7236

7337
// Handle chat subdomains
7438
if (subdomain && isCustomDomain) {
75-
// Special case for API requests from the subdomain
7639
if (url.pathname.startsWith('/api/chat/')) {
77-
// Already an API request, let it go through
7840
return NextResponse.next()
7941
}
8042

0 commit comments

Comments
 (0)