Skip to content

Commit

Permalink
build(viewer): 🔊 Better log when can't find a typebot
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed May 20, 2022
1 parent 24b077c commit 0f06aae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
21 changes: 19 additions & 2 deletions apps/viewer/layouts/ErrorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,25 @@ export const ErrorPage = ({ error }: { error: Error }) => {
flexDirection: 'column',
}}
>
<h1 style={{ fontWeight: 'bold', fontSize: '30px' }}>{error.name}</h1>
<h2>{error.message}</h2>
{!process.env.NEXT_PUBLIC_VIEWER_URL ? (
<>
<h1 style={{ fontWeight: 'bold', fontSize: '30px' }}>
NEXT_PUBLIC_VIEWER_URL is missing
</h1>
<h2>
Make sure to configure the viewer properly (
<a href="https://docs.typebot.io/self-hosting/configuration#viewer">
https://docs.typebot.io/self-hosting/configuration#viewer
</a>
)
</h2>
</>
) : (
<>
<h1 style={{ fontWeight: 'bold', fontSize: '30px' }}>{error.name}</h1>
<h2>{error.message}</h2>
</>
)}
</div>
)
}
16 changes: 12 additions & 4 deletions apps/viewer/pages/[[...publicId]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

4 comments on commit 0f06aae

@vercel
Copy link

@vercel vercel bot commented on 0f06aae May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0f06aae May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 0f06aae May 20, 2022

@vercel
Copy link

@vercel vercel bot commented on 0f06aae May 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.