fix: 🚑️ Custom domain lookup
This commit is contained in:
@ -11,14 +11,16 @@ export const getServerSideProps: GetServerSideProps = async (
|
|||||||
let typebot: Omit<PublicTypebot, 'createdAt' | 'updatedAt'> | null
|
let typebot: Omit<PublicTypebot, 'createdAt' | 'updatedAt'> | null
|
||||||
const isIE = /MSIE|Trident/.test(context.req.headers['user-agent'] ?? '')
|
const isIE = /MSIE|Trident/.test(context.req.headers['user-agent'] ?? '')
|
||||||
const pathname = context.resolvedUrl.split('?')[0]
|
const pathname = context.resolvedUrl.split('?')[0]
|
||||||
|
console.log('pathname:', pathname)
|
||||||
try {
|
try {
|
||||||
if (!context.req.headers.host) return { props: {} }
|
if (!context.req.headers.host) return { props: {} }
|
||||||
|
console.log('context.req.headers.host:', context.req.headers.host)
|
||||||
typebot = context.req.headers.host.includes(
|
typebot = context.req.headers.host.includes(
|
||||||
(process.env.NEXT_PUBLIC_VIEWER_URL ?? '').split('//')[1]
|
(process.env.NEXT_PUBLIC_VIEWER_URL ?? '').split('//')[1]
|
||||||
)
|
)
|
||||||
? await getTypebotFromPublicId(context.query.publicId?.toString())
|
? await getTypebotFromPublicId(context.query.publicId?.toString())
|
||||||
: await getTypebotFromCustomDomain(
|
: await getTypebotFromCustomDomain(
|
||||||
`${context.req.headers.host}${pathname}`
|
`${context.req.headers.host}${pathname === '/' ? '' : pathname}`
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
@ -48,8 +50,8 @@ const getTypebotFromPublicId = async (publicId?: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getTypebotFromCustomDomain = async (customDomain: string) => {
|
const getTypebotFromCustomDomain = async (customDomain: string) => {
|
||||||
const typebot = await prisma.publicTypebot.findUnique({
|
const typebot = await prisma.publicTypebot.findFirst({
|
||||||
where: { customDomain },
|
where: { customDomain: { contains: customDomain } },
|
||||||
})
|
})
|
||||||
if (isNotDefined(typebot)) return null
|
if (isNotDefined(typebot)) return null
|
||||||
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
||||||
|
Reference in New Issue
Block a user