2
0

build(viewer): 🔊 Better log when can't find a typebot

This commit is contained in:
Baptiste Arnaud
2022-05-20 14:14:37 -07:00
parent 24b077c0e2
commit 0f06aae80c
2 changed files with 31 additions and 6 deletions

View File

@ -14,13 +14,21 @@ export const getServerSideProps: GetServerSideProps = async (
try {
if (!context.req.headers.host) return { props: {} }
const viewerUrls = (process.env.NEXT_PUBLIC_VIEWER_URL ?? '').split(',')
typebot = viewerUrls.some((url) =>
const isMatchingViewerUrl = viewerUrls.some((url) =>
context.req.headers.host?.includes(url.split('//')[1])
)
const customDomain = `${context.req.headers.host}${
pathname === '/' ? '' : pathname
}`
typebot = isMatchingViewerUrl
? await getTypebotFromPublicId(context.query.publicId?.toString())
: await getTypebotFromCustomDomain(
`${context.req.headers.host}${pathname === '/' ? '' : pathname}`
)
: await getTypebotFromCustomDomain(customDomain)
if (!typebot)
console.log(
isMatchingViewerUrl
? `Couldn't find publicId: ${context.query.publicId?.toString()}`
: `Couldn't customDomain: ${customDomain}`
)
return {
props: {
typebot,