From 666f0c36bf02c6d7d442cb6a2b5414651399a453 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 14 Mar 2022 16:54:37 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20Custom=20domain?= =?UTF-8?q?=20lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/viewer/pages/[[...publicId]].tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/viewer/pages/[[...publicId]].tsx b/apps/viewer/pages/[[...publicId]].tsx index 921474329..398926d12 100644 --- a/apps/viewer/pages/[[...publicId]].tsx +++ b/apps/viewer/pages/[[...publicId]].tsx @@ -11,14 +11,16 @@ export const getServerSideProps: GetServerSideProps = async ( let typebot: Omit | null const isIE = /MSIE|Trident/.test(context.req.headers['user-agent'] ?? '') const pathname = context.resolvedUrl.split('?')[0] + console.log('pathname:', pathname) try { if (!context.req.headers.host) return { props: {} } + console.log('context.req.headers.host:', context.req.headers.host) typebot = context.req.headers.host.includes( (process.env.NEXT_PUBLIC_VIEWER_URL ?? '').split('//')[1] ) ? await getTypebotFromPublicId(context.query.publicId?.toString()) : await getTypebotFromCustomDomain( - `${context.req.headers.host}${pathname}` + `${context.req.headers.host}${pathname === '/' ? '' : pathname}` ) return { props: { @@ -48,8 +50,8 @@ const getTypebotFromPublicId = async (publicId?: string) => { } const getTypebotFromCustomDomain = async (customDomain: string) => { - const typebot = await prisma.publicTypebot.findUnique({ - where: { customDomain }, + const typebot = await prisma.publicTypebot.findFirst({ + where: { customDomain: { contains: customDomain } }, }) if (isNotDefined(typebot)) return null return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')