From a2dd26b60f7e28c141f9df7066c9045bbcdc7571 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Mon, 23 May 2022 14:16:43 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(viewer):=20=F0=9F=90=9B=20Forward?= =?UTF-8?q?ed=20host=20checking"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 37dea9c4030f06f8e73ba6ebc773a17ca9a6f911. --- apps/viewer/pages/[[...publicId]].tsx | 30 ++++++++------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/apps/viewer/pages/[[...publicId]].tsx b/apps/viewer/pages/[[...publicId]].tsx index 5af8cea3e..a4c11c947 100644 --- a/apps/viewer/pages/[[...publicId]].tsx +++ b/apps/viewer/pages/[[...publicId]].tsx @@ -1,4 +1,3 @@ -import { IncomingMessage } from 'http' import { NotFoundPage } from 'layouts/NotFoundPage' import { PublicTypebot } from 'models' import { GetServerSideProps, GetServerSidePropsContext } from 'next' @@ -12,14 +11,17 @@ export const getServerSideProps: GetServerSideProps = async ( let typebot: Omit | null const isIE = /MSIE|Trident/.test(context.req.headers['user-agent'] ?? '') const pathname = context.resolvedUrl.split('?')[0] - const host = getHost(context.req) try { - if (!host) return { props: {} } + if (!context.req.headers.host) return { props: {} } const viewerUrls = (process.env.NEXT_PUBLIC_VIEWER_URL ?? '').split(',') const isMatchingViewerUrl = viewerUrls.some((url) => - host.split(':')[0].includes(url.split('//')[1].split(':')[0]) + (context.req.headers.host ?? '') + .split(':')[0] + .includes(url.split('//')[1].split(':')[0]) ) - const customDomain = `${host}${pathname === '/' ? '' : pathname}` + const customDomain = `${context.req.headers.host}${ + pathname === '/' ? '' : pathname + }` typebot = isMatchingViewerUrl ? await getTypebotFromPublicId(context.query.publicId?.toString()) : await getTypebotFromCustomDomain(customDomain) @@ -33,7 +35,7 @@ export const getServerSideProps: GetServerSideProps = async ( props: { typebot, isIE, - url: `https://${host}${pathname}`, + url: `https://${context.req.headers.host}${pathname}`, }, } } catch (err) { @@ -42,7 +44,7 @@ export const getServerSideProps: GetServerSideProps = async ( return { props: { isIE, - url: `https://${host}${pathname}`, + url: `https://${context.req.headers.host}${pathname}`, }, } } @@ -64,20 +66,6 @@ const getTypebotFromCustomDomain = async (customDomain: string) => { return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt') } -const getHost = (req?: IncomingMessage): string | undefined => { - let host = req?.headers ? req.headers.host : window.location.host - if (!host) return - if ( - req && - req.headers['x-forwarded-host'] && - typeof req.headers['x-forwarded-host'] === 'string' - ) { - host = req.headers['x-forwarded-host'] - } - - return host -} - const App = ({ typebot, ...props }: TypebotPageProps) => isDefined(typebot) ? (