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
+
+
+ >
+ ) : (
+ <>
+ {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,