2
0

fix(viewer): 💚 Attempt to fix LP rewrites

This commit is contained in:
Baptiste Arnaud
2022-02-10 16:23:21 +01:00
parent 92515efcc3
commit 19f4fdb83a
11 changed files with 65 additions and 73 deletions

View File

@ -30,7 +30,7 @@ export const EditableUrl = ({
onSubmit={onPublicIdChange} onSubmit={onPublicIdChange}
> >
<HStack spacing={1}> <HStack spacing={1}>
<Text>https://</Text> <Text>{process.env.NEXT_PUBLIC_VIEWER_HOST}/</Text>
<Tooltip label="Edit"> <Tooltip label="Edit">
<EditablePreview <EditablePreview
mx={1} mx={1}
@ -43,15 +43,15 @@ export const EditableUrl = ({
fontWeight="semibold" fontWeight="semibold"
/> />
</Tooltip> </Tooltip>
<EditableInput px={2} /> <EditableInput px={2} />
<Text>.typebot.io/</Text>
</HStack> </HStack>
<HStack> <HStack>
<EditButton size="xs" /> <EditButton size="xs" />
<CopyButton size="xs" textToCopy={`https://${publicId}.typebot.io/`} /> <CopyButton
size="xs"
textToCopy={`${process.env.NEXT_PUBLIC_VIEWER_HOST}/${publicId}`}
/>
</HStack> </HStack>
</Editable> </Editable>
) )

View File

@ -4,7 +4,6 @@ import {
PublicBlock, PublicBlock,
PublicStep, PublicStep,
PublicTypebot, PublicTypebot,
Step,
Typebot, Typebot,
} from 'models' } from 'models'
import shortId from 'short-uuid' import shortId from 'short-uuid'
@ -17,10 +16,15 @@ import { isDefined } from '@udecode/plate-common'
export const parseTypebotToPublicTypebot = ( export const parseTypebotToPublicTypebot = (
typebot: Typebot typebot: Typebot
): PublicTypebot => ({ ): PublicTypebot => ({
...typebot,
id: shortId.generate(), id: shortId.generate(),
typebotId: typebot.id, typebotId: typebot.id,
blocks: parseBlocksToPublicBlocks(typebot.blocks), blocks: parseBlocksToPublicBlocks(typebot.blocks),
edges: typebot.edges,
name: typebot.name,
publicId: typebot.publicId,
settings: typebot.settings,
theme: typebot.theme,
variables: typebot.variables,
}) })
const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] => const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>

View File

@ -0,0 +1,4 @@
NOTION_API_TOKEN=
NOTION_DATABASE_ID=
NEXT_PUBLIC_VIEWER_HOST=http://localhost:3001
LANDING_PAGE_HOST=http://localhost:3002

View File

@ -10,6 +10,16 @@ const securityHeaders = [
}, },
] ]
const pages = [
'blog',
'pricing',
'privacy-policies',
'terms-of-service',
'vs-landbot',
'vs-tally',
'vs-typeform',
]
module.exports = withBundleAnalyzer({ module.exports = withBundleAnalyzer({
async headers() { async headers() {
return [ return [
@ -30,11 +40,31 @@ module.exports = withBundleAnalyzer({
] ]
}, },
async rewrites() { async rewrites() {
return [ return {
{ beforeFiles: [
source: '/:path*', {
destination: `${process.env.NEXT_PUBLIC_VIEWER_HOST}/:path*`, source: '/_next/static/:static*',
}, destination:
] process.env.NEXT_PUBLIC_VIEWER_HOST + '/_next/static/:static*',
has: [
{
type: 'header',
key: 'referer',
value:
process.env.LANDING_PAGE_HOST +
'/(?!' +
pages.join('|') +
'|\\?).+',
},
],
},
],
fallback: [
{
source: '/:user*',
destination: process.env.NEXT_PUBLIC_VIEWER_HOST + '/:user*',
},
],
}
}, },
}) })

View File

@ -15,13 +15,14 @@ import {
} from '@chakra-ui/react' } from '@chakra-ui/react'
import loadLandbot from '../lib/landbot' import loadLandbot from '../lib/landbot'
import Image from 'next/image' import Image from 'next/image'
import Typebot from 'typebot-js' import { initContainer } from 'typebot-js'
import { ArticleCallToAction } from 'components/common/ArticleCta' import { ArticleCallToAction } from 'components/common/ArticleCta'
import { Footer } from 'components/common/Footer' import { Footer } from 'components/common/Footer'
import { Navbar } from 'components/common/Navbar/Navbar' import { Navbar } from 'components/common/Navbar/Navbar'
import { NextChakraLink } from 'components/common/nextChakraAdapters/NextChakraLink' import { NextChakraLink } from 'components/common/nextChakraAdapters/NextChakraLink'
import { SocialMetaTags } from 'components/common/SocialMetaTags' import { SocialMetaTags } from 'components/common/SocialMetaTags'
import { Yes, No } from 'components/common/TableCells' import { Yes, No } from 'components/common/TableCells'
import landbotVisualFlowSrc from 'public/images/landbot/visual-flow.png'
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const Landbot: any declare const Landbot: any
@ -35,7 +36,7 @@ const VsTypebot = () => {
'https://chats.landbot.io/v3/H-937813-ZLZEY720UH1TWN5S/index.json', 'https://chats.landbot.io/v3/H-937813-ZLZEY720UH1TWN5S/index.json',
}) })
}) })
Typebot.initContainer('typebot-container', { initContainer('typebot-container', {
publishId: 'example-vs-other-tools', publishId: 'example-vs-other-tools',
}) })
}, []) }, [])
@ -91,7 +92,7 @@ const VsTypebot = () => {
</Text> </Text>
<Box h="400px" pos="relative"> <Box h="400px" pos="relative">
<Image <Image
src="landbotVisualFlowSrc" src={landbotVisualFlowSrc}
layout="fill" layout="fill"
objectFit="contain" objectFit="contain"
alt="Visual flow screenshot" alt="Visual flow screenshot"

View File

@ -12,7 +12,7 @@ import {
Th, Th,
Flex, Flex,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import Typebot from 'typebot-js' import { initContainer } from 'typebot-js'
import { ArticleCallToAction } from 'components/common/ArticleCta' import { ArticleCallToAction } from 'components/common/ArticleCta'
import { roadmapLink, Footer } from 'components/common/Footer' import { roadmapLink, Footer } from 'components/common/Footer'
import { Navbar } from 'components/common/Navbar/Navbar' import { Navbar } from 'components/common/Navbar/Navbar'
@ -22,7 +22,7 @@ import { Yes, No } from 'components/common/TableCells'
const VsTypebot = () => { const VsTypebot = () => {
useEffect(() => { useEffect(() => {
Typebot.initContainer('typebot-container', { initContainer('typebot-container', {
publishId: 'example-vs-other-tools', publishId: 'example-vs-other-tools',
}) })
}, []) }, [])

View File

@ -12,7 +12,7 @@ import {
Th, Th,
Flex, Flex,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import Typebot from 'typebot-js' import { initContainer } from 'typebot-js'
import { CheckIcon } from 'assets/icons/CheckIcon' import { CheckIcon } from 'assets/icons/CheckIcon'
import { CloseIcon } from 'assets/icons/CloseIcon' import { CloseIcon } from 'assets/icons/CloseIcon'
import { ArticleCallToAction } from 'components/common/ArticleCta' import { ArticleCallToAction } from 'components/common/ArticleCta'
@ -25,7 +25,7 @@ import loadTypeform from 'lib/typeform'
const VsTypebot = () => { const VsTypebot = () => {
useEffect(() => { useEffect(() => {
loadTypeform().then() loadTypeform().then()
Typebot.initContainer('typebot-container', { initContainer('typebot-container', {
publishId: 'example-vs-other-tools', publishId: 'example-vs-other-tools',
}) })
}, []) }, [])

View File

@ -7,7 +7,7 @@ import prisma from '../libs/prisma'
export const getServerSideProps: GetServerSideProps = async ( export const getServerSideProps: GetServerSideProps = async (
context: GetServerSidePropsContext context: GetServerSidePropsContext
) => { ) => {
let typebot: PublicTypebot | undefined let typebot: PublicTypebot | 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]
try { try {
@ -33,12 +33,12 @@ export const getServerSideProps: GetServerSideProps = async (
const getTypebotFromPublicId = async ( const getTypebotFromPublicId = async (
publicId?: string publicId?: string
): Promise<PublicTypebot | undefined> => { ): Promise<PublicTypebot | null> => {
if (!publicId) return if (!publicId) return null
const typebot = await prisma.publicTypebot.findUnique({ const typebot = await prisma.publicTypebot.findUnique({
where: { publicId }, where: { publicId },
}) })
return (typebot as unknown as PublicTypebot | undefined) ?? undefined return (typebot as unknown as PublicTypebot) ?? null
} }
const App = ({ typebot, ...props }: TypebotPageProps) => const App = ({ typebot, ...props }: TypebotPageProps) =>

View File

@ -1,47 +0,0 @@
import { NotFoundPage } from 'layouts/NotFoundPage'
import { PublicTypebot } from 'models'
import { GetServerSideProps, GetServerSidePropsContext } from 'next'
import { TypebotPage, TypebotPageProps } from '../layouts/TypebotPage'
import prisma from '../libs/prisma'
export const getServerSideProps: GetServerSideProps = async (
context: GetServerSidePropsContext
) => {
let typebot: PublicTypebot | undefined
const isIE = /MSIE|Trident/.test(context.req.headers['user-agent'] ?? '')
const pathname = context.resolvedUrl.split('?')[0]
try {
if (!context.req.headers.host) return { props: {} }
typebot = await getTypebotFromUrl(context.req.headers.host)
return {
props: {
typebot,
isIE,
url: `https://${context.req.headers.host}${pathname}`,
},
}
} catch (err) {
console.error(err)
}
return {
props: {
isIE,
url: `https://${context.req.headers.host}${pathname}`,
},
}
}
const getTypebotFromUrl = async (
hostname: string
): Promise<PublicTypebot | undefined> => {
const publicId = hostname.split('.').shift()
if (!publicId) return
const typebot = await prisma.publicTypebot.findUnique({
where: { publicId },
})
return (typebot as unknown as PublicTypebot | undefined) ?? undefined
}
const App = ({ typebot, ...props }: TypebotPageProps) =>
typebot ? <TypebotPage {...props} typebot={typebot} /> : <NotFoundPage />
export default App

View File

@ -16,7 +16,7 @@
}, },
"devDependencies": { "devDependencies": {
"dotenv-cli": "^4.1.1", "dotenv-cli": "^4.1.1",
"turbo": "^1.1.1" "turbo": "^1.1.2"
}, },
"packageManager": "yarn@1.22.17" "packageManager": "yarn@1.22.17"
} }

View File

@ -8073,7 +8073,7 @@ turbo-windows-64@1.1.2:
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.1.2.tgz#8eb3f77ab7e04b077752ae2204114c82e5c74697" resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.1.2.tgz#8eb3f77ab7e04b077752ae2204114c82e5c74697"
integrity sha512-0Ncx/iKhnKrdAU8hJ+8NUcF9jtFr8KoW5mMWfiFzy+mgUbVKbpzWT2eoGR6zJExedQsRvYOejbEX5iihbnj5bA== integrity sha512-0Ncx/iKhnKrdAU8hJ+8NUcF9jtFr8KoW5mMWfiFzy+mgUbVKbpzWT2eoGR6zJExedQsRvYOejbEX5iihbnj5bA==
turbo@^1.1.1: turbo@^1.1.2:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/turbo/-/turbo-1.1.2.tgz#751b9651dc3ebe469898db76afab6405666ad0ff" resolved "https://registry.yarnpkg.com/turbo/-/turbo-1.1.2.tgz#751b9651dc3ebe469898db76afab6405666ad0ff"
integrity sha512-3ViHKyAkaBKNKwHASTa1zkVT3tVVhQNLrpxBS7LoN+794ouQUYmy6lf0rTqzG3iTZHtIDwC+piZSdTl4XjEVMg== integrity sha512-3ViHKyAkaBKNKwHASTa1zkVT3tVVhQNLrpxBS7LoN+794ouQUYmy6lf0rTqzG3iTZHtIDwC+piZSdTl4XjEVMg==