mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
fix(whitelabel): move redirects (build-time) for whitelabeling to middlware (runtime) (#1236)
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user