fix(chat-deploy): fix chat deploy URL in prod (#767)

This commit is contained in:
Waleed Latif
2025-07-23 02:12:21 -07:00
committed by GitHub
parent a599d3ae0a
commit e90138a651
3 changed files with 13 additions and 9 deletions

View File

@@ -4,7 +4,7 @@ import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { isDev } from '@/lib/environment'
import { createLogger } from '@/lib/logs/console-logger'
import { getBaseDomain } from '@/lib/urls/utils'
import { getEmailDomain } from '@/lib/urls/utils'
import { encryptSecret } from '@/lib/utils'
import { checkChatAccess } from '@/app/api/chat/utils'
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
@@ -68,7 +68,7 @@ export async function GET(_request: NextRequest, { params }: { params: Promise<{
// Create a new result object without the password
const { password, ...safeData } = chatRecord
const baseDomain = getBaseDomain()
const baseDomain = getEmailDomain()
const protocol = isDev ? 'http' : 'https'
const chatUrl = `${protocol}://${chatRecord.subdomain}.${baseDomain}`
@@ -214,7 +214,7 @@ export async function PATCH(request: NextRequest, { params }: { params: Promise<
const updatedSubdomain = subdomain || existingChat[0].subdomain
const baseDomain = getBaseDomain()
const baseDomain = getEmailDomain()
const protocol = isDev ? 'http' : 'https'
const chatUrl = `${protocol}://${updatedSubdomain}.${baseDomain}`

View File

@@ -175,7 +175,11 @@ export async function POST(request: NextRequest) {
let chatUrl: string
try {
const url = new URL(baseUrl)
chatUrl = `${url.protocol}//${subdomain}.${url.host}`
let host = url.host
if (host.startsWith('www.')) {
host = host.substring(4)
}
chatUrl = `${url.protocol}//${subdomain}.${host}`
} catch (error) {
logger.warn('Failed to parse baseUrl, falling back to defaults:', {
baseUrl,

View File

@@ -31,7 +31,7 @@ import { Label } from '@/components/ui/label'
import { Skeleton } from '@/components/ui/skeleton'
import { Textarea } from '@/components/ui/textarea'
import { createLogger } from '@/lib/logs/console-logger'
import { getBaseDomain } from '@/lib/urls/utils'
import { getBaseDomain, getEmailDomain } from '@/lib/urls/utils'
import { cn } from '@/lib/utils'
import { OutputSelect } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/chat/components/output-select/output-select'
import type { OutputConfig } from '@/stores/panel/chat/types'
@@ -53,7 +53,7 @@ interface ChatDeployProps {
type AuthType = 'public' | 'password' | 'email'
const getDomainSuffix = (() => {
const suffix = `.${getBaseDomain()}`
const suffix = `.${getEmailDomain()}`
return () => suffix
})()
@@ -772,10 +772,10 @@ export function ChatDeploy({
const port = url.port || (baseDomain.includes(':') ? baseDomain.split(':')[1] : '3000')
domainSuffix = `.${baseHost}:${port}`
} else {
domainSuffix = `.${getBaseDomain()}`
domainSuffix = `.${getEmailDomain()}`
}
const baseDomainForSplit = getBaseDomain()
const baseDomainForSplit = getEmailDomain()
const subdomainPart = isDevelopmentUrl
? hostname.split('.')[0]
: hostname.split(`.${baseDomainForSplit}`)[0]
@@ -1248,7 +1248,7 @@ export function ChatDeploy({
<AlertDialogDescription>
This will permanently delete your chat deployment at{' '}
<span className='font-mono text-destructive'>
{subdomain}.{getBaseDomain()}
{subdomain}.{getEmailDomain()}
</span>
.
<p className='mt-2'>