Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/sim/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ export async function middleware(request: NextRequest) {
return NextResponse.redirect(new URL('/login', request.url))
}

// Handle whitelabel redirects for terms and privacy pages
if (url.pathname === '/terms') {
const termsUrl = process.env.NEXT_PUBLIC_TERMS_URL
if (termsUrl?.startsWith('http')) {
return NextResponse.redirect(termsUrl)
}
}

if (url.pathname === '/privacy') {
const privacyUrl = process.env.NEXT_PUBLIC_PRIVACY_URL
if (privacyUrl?.startsWith('http')) {
return NextResponse.redirect(privacyUrl)
}
}

// Legacy redirect: /w -> /workspace (will be handled by workspace layout)
if (url.pathname === '/w' || url.pathname.startsWith('/w/')) {
// Extract workflow ID if present
Expand Down Expand Up @@ -195,6 +210,8 @@ export async function middleware(request: NextRequest) {
export const config = {
matcher: [
'/', // Root path for self-hosted redirect logic
'/terms', // Whitelabel terms redirect
'/privacy', // Whitelabel privacy redirect
'/w', // Legacy /w redirect
'/w/:path*', // Legacy /w/* redirects
'/workspace/:path*', // New workspace routes
Expand Down
20 changes: 1 addition & 19 deletions apps/sim/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withSentryConfig } from '@sentry/nextjs'
import type { NextConfig } from 'next'
import { env, getEnv, isTruthy } from './lib/env'
import { env, isTruthy } from './lib/env'
import { isDev, isHosted, isProd } from './lib/environment'
import { getMainCSPPolicy, getWorkflowExecutionCSPPolicy } from './lib/security/csp'

Expand Down Expand Up @@ -186,24 +186,6 @@ const nextConfig: NextConfig = {
},
async redirects() {
const redirects = []
// Add whitelabel redirects for terms and privacy pages if external URLs are configured
const termsUrl = getEnv('NEXT_PUBLIC_TERMS_URL')
if (termsUrl?.startsWith('http')) {
redirects.push({
source: '/terms',
destination: termsUrl,
permanent: false,
})
}

const privacyUrl = getEnv('NEXT_PUBLIC_PRIVACY_URL')
if (privacyUrl?.startsWith('http')) {
redirects.push({
source: '/privacy',
destination: privacyUrl,
permanent: false,
})
}

// Only enable domain redirects for the hosted version
if (isHosted) {
Expand Down