From 0f06aae80cd12ad350c80d959992ba010fadd958 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 20 May 2022 14:14:37 -0700 Subject: [PATCH] =?UTF-8?q?build(viewer):=20=F0=9F=94=8A=20Better=20log=20?= =?UTF-8?q?when=20can't=20find=20a=20typebot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/viewer/layouts/ErrorPage.tsx | 21 +++++++++++++++++++-- apps/viewer/pages/[[...publicId]].tsx | 16 ++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/apps/viewer/layouts/ErrorPage.tsx b/apps/viewer/layouts/ErrorPage.tsx index d734f4af4..595a6ea0e 100644 --- a/apps/viewer/layouts/ErrorPage.tsx +++ b/apps/viewer/layouts/ErrorPage.tsx @@ -11,8 +11,25 @@ export const ErrorPage = ({ error }: { error: Error }) => { flexDirection: 'column', }} > -

{error.name}

-

{error.message}

+ {!process.env.NEXT_PUBLIC_VIEWER_URL ? ( + <> +

+ NEXT_PUBLIC_VIEWER_URL is missing +

+

+ Make sure to configure the viewer properly ( + + https://docs.typebot.io/self-hosting/configuration#viewer + + ) +

+ + ) : ( + <> +

{error.name}

+

{error.message}

+ + )} ) } diff --git a/apps/viewer/pages/[[...publicId]].tsx b/apps/viewer/pages/[[...publicId]].tsx index 2a648c799..d0383f960 100644 --- a/apps/viewer/pages/[[...publicId]].tsx +++ b/apps/viewer/pages/[[...publicId]].tsx @@ -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,