diff --git a/sim/app/(auth)/verify/page.tsx b/sim/app/(auth)/verify/page.tsx index 3ec593fd4d..7a2459c8cf 100644 --- a/sim/app/(auth)/verify/page.tsx +++ b/sim/app/(auth)/verify/page.tsx @@ -1,10 +1,9 @@ import { isProd } from '@/lib/environment' import { VerifyContent } from './verify-content' +import { getBaseUrl } from '@/lib/urls/utils' export default function VerifyPage() { - const protocol = isProd ? 'https' : 'http' - const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'localhost:3000' - const baseUrl = `${protocol}://${appUrl}` + const baseUrl = getBaseUrl() const hasResendKey = Boolean( process.env.RESEND_API_KEY && process.env.RESEND_API_KEY !== 'placeholder' diff --git a/sim/app/api/chat/edit/[id]/route.ts b/sim/app/api/chat/edit/[id]/route.ts index 24ebcbbee1..7577d6a5e6 100644 --- a/sim/app/api/chat/edit/[id]/route.ts +++ b/sim/app/api/chat/edit/[id]/route.ts @@ -7,6 +7,7 @@ import { chat } from '@/db/schema' import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils' import { z } from 'zod' import { encryptSecret } from '@/lib/utils' +import { getBaseDomain } from '@/lib/urls/utils' export const dynamic = 'force-dynamic' @@ -67,17 +68,15 @@ export async function GET( // Create a new result object without the password const { password, ...safeData } = chatInstance[0] - // Check if we're in development or production const isDevelopment = process.env.NODE_ENV === 'development' + const chatUrl = isDevelopment - ? `http://${chatInstance[0].subdomain}.localhost:3000` + ? `http://${chatInstance[0].subdomain}.${getBaseDomain()}` : `https://${chatInstance[0].subdomain}.simstudio.ai` - // For security, don't return the actual password value const result = { ...safeData, chatUrl, - // Include password presence flag but not the actual value hasPassword: !!password } @@ -228,12 +227,12 @@ export async function PATCH( .set(updateData) .where(eq(chat.id, chatId)) - // Return success response const updatedSubdomain = subdomain || existingChat[0].subdomain - // Check if we're in development or production + const isDevelopment = process.env.NODE_ENV === 'development' + const chatUrl = isDevelopment - ? `http://${updatedSubdomain}.localhost:3000` + ? `http://${updatedSubdomain}.${getBaseDomain()}` : `https://${updatedSubdomain}.simstudio.ai` logger.info(`Chat "${chatId}" updated successfully`) diff --git a/sim/app/w/[id]/components/control-bar/components/deploy-modal/components/chat-deploy/chat-deploy.tsx b/sim/app/w/[id]/components/control-bar/components/deploy-modal/components/chat-deploy/chat-deploy.tsx index 0ab8cfdef0..fb95ee9d39 100644 --- a/sim/app/w/[id]/components/control-bar/components/deploy-modal/components/chat-deploy/chat-deploy.tsx +++ b/sim/app/w/[id]/components/control-bar/components/deploy-modal/components/chat-deploy/chat-deploy.tsx @@ -32,6 +32,7 @@ import { Skeleton } from '@/components/ui/skeleton' import { Textarea } from '@/components/ui/textarea' import { createLogger } from '@/lib/logs/console-logger' import { cn } from '@/lib/utils' +import { getBaseDomain } from '@/lib/urls/utils' import { useNotificationStore } from '@/stores/notifications/store' import { OutputSelect } from '@/app/w/[id]/components/panel/components/chat/components/output-select/output-select' import { OutputConfig } from '@/stores/panel/chat/types' @@ -54,6 +55,11 @@ type AuthType = 'public' | 'password' | 'email' const isDevelopment = process.env.NODE_ENV === 'development' +const getDomainSuffix = (() => { + const suffix = isDevelopment ? `.${getBaseDomain()}` : '.simstudio.ai' + return () => suffix +})() + // Define Zod schema for API request validation const chatSchema = z.object({ workflowId: z.string().min(1, 'Workflow ID is required'), @@ -810,11 +816,20 @@ export function ChatDeploy({ } if (deployedChatUrl) { - // Extract just the subdomain from the URL const url = new URL(deployedChatUrl) const hostname = url.hostname const isDevelopmentUrl = hostname.includes('localhost') - const domainSuffix = isDevelopmentUrl ? '.localhost:3000' : '.simstudio.ai' + + let domainSuffix + if (isDevelopmentUrl) { + const baseDomain = getBaseDomain() + const baseHost = baseDomain.split(':')[0] + const port = url.port || (baseDomain.includes(':') ? baseDomain.split(':')[1] : '3000') + domainSuffix = `.${baseHost}:${port}` + } else { + domainSuffix = '.simstudio.ai' + } + const subdomainPart = isDevelopmentUrl ? hostname.split('.')[0] : hostname.split('.simstudio.ai')[0] @@ -911,7 +926,7 @@ export function ChatDeploy({ disabled={isDeploying} />