Skip to content

Commit 1de5966

Browse files
authored
fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime) (#1236)
1 parent 26243b9 commit 1de5966

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

apps/sim/middleware.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ export async function middleware(request: NextRequest) {
8383
return NextResponse.redirect(new URL('/login', request.url))
8484
}
8585

86+
// Handle whitelabel redirects for terms and privacy pages
87+
if (url.pathname === '/terms') {
88+
const termsUrl = process.env.NEXT_PUBLIC_TERMS_URL
89+
if (termsUrl?.startsWith('http')) {
90+
return NextResponse.redirect(termsUrl)
91+
}
92+
}
93+
94+
if (url.pathname === '/privacy') {
95+
const privacyUrl = process.env.NEXT_PUBLIC_PRIVACY_URL
96+
if (privacyUrl?.startsWith('http')) {
97+
return NextResponse.redirect(privacyUrl)
98+
}
99+
}
100+
86101
// Legacy redirect: /w -> /workspace (will be handled by workspace layout)
87102
if (url.pathname === '/w' || url.pathname.startsWith('/w/')) {
88103
// Extract workflow ID if present
@@ -195,6 +210,8 @@ export async function middleware(request: NextRequest) {
195210
export const config = {
196211
matcher: [
197212
'/', // Root path for self-hosted redirect logic
213+
'/terms', // Whitelabel terms redirect
214+
'/privacy', // Whitelabel privacy redirect
198215
'/w', // Legacy /w redirect
199216
'/w/:path*', // Legacy /w/* redirects
200217
'/workspace/:path*', // New workspace routes

apps/sim/next.config.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { withSentryConfig } from '@sentry/nextjs'
22
import type { NextConfig } from 'next'
3-
import { env, getEnv, isTruthy } from './lib/env'
3+
import { env, isTruthy } from './lib/env'
44
import { isDev, isHosted, isProd } from './lib/environment'
55
import { getMainCSPPolicy, getWorkflowExecutionCSPPolicy } from './lib/security/csp'
66

@@ -186,24 +186,6 @@ const nextConfig: NextConfig = {
186186
},
187187
async redirects() {
188188
const redirects = []
189-
// Add whitelabel redirects for terms and privacy pages if external URLs are configured
190-
const termsUrl = getEnv('NEXT_PUBLIC_TERMS_URL')
191-
if (termsUrl?.startsWith('http')) {
192-
redirects.push({
193-
source: '/terms',
194-
destination: termsUrl,
195-
permanent: false,
196-
})
197-
}
198-
199-
const privacyUrl = getEnv('NEXT_PUBLIC_PRIVACY_URL')
200-
if (privacyUrl?.startsWith('http')) {
201-
redirects.push({
202-
source: '/privacy',
203-
destination: privacyUrl,
204-
permanent: false,
205-
})
206-
}
207189

208190
// Only enable domain redirects for the hosted version
209191
if (isHosted) {

0 commit comments

Comments
 (0)