diff --git a/apps/web/app/WithEmbedSSR.tsx b/apps/web/app/WithEmbedSSR.tsx index c19ead200d..a7d5387425 100644 --- a/apps/web/app/WithEmbedSSR.tsx +++ b/apps/web/app/WithEmbedSSR.tsx @@ -3,7 +3,7 @@ import { isNotFoundError } from "next/dist/client/components/not-found"; import { getURLFromRedirectError, isRedirectError } from "next/dist/client/components/redirect"; import { notFound, redirect } from "next/navigation"; -import { WEBAPP_URL } from "@calcom/lib/constants"; +import { WebAppURL } from "@calcom/lib/WebAppURL"; export type EmbedProps = { isEmbed?: boolean; @@ -28,7 +28,7 @@ export default function withEmbedSsrAppDir>( let urlPrefix = ""; // Get the URL parsed from URL so that we can reliably read pathname and searchParams from it. - const destinationUrlObj = new URL(destinationUrl, WEBAPP_URL); + const destinationUrlObj = new WebAppURL(destinationUrl); // If it's a complete URL, use the origin as the prefix to ensure we redirect to the same domain. if (destinationUrl.search(/^(http:|https:).*/) !== -1) { diff --git a/apps/web/lib/withEmbedSsr.tsx b/apps/web/lib/withEmbedSsr.tsx index 228e6a2c4a..19a98ee263 100644 --- a/apps/web/lib/withEmbedSsr.tsx +++ b/apps/web/lib/withEmbedSsr.tsx @@ -1,6 +1,6 @@ import type { GetServerSideProps, GetServerSidePropsContext, GetServerSidePropsResult } from "next"; -import { WEBAPP_URL } from "@calcom/lib/constants"; +import { WebAppURL } from "@calcom/lib/WebAppURL"; export type EmbedProps = { isEmbed?: boolean; @@ -17,7 +17,7 @@ export default function withEmbedSsr(getServerSideProps: GetServerSideProps) { let urlPrefix = ""; // Get the URL parsed from URL so that we can reliably read pathname and searchParams from it. - const destinationUrlObj = new URL(ssrResponse.redirect.destination, WEBAPP_URL); + const destinationUrlObj = new WebAppURL(ssrResponse.redirect.destination); // If it's a complete URL, use the origin as the prefix to ensure we redirect to the same domain. if (destinationUrl.search(/^(http:|https:).*/) !== -1) { diff --git a/packages/lib/WebAppURL.ts b/packages/lib/WebAppURL.ts new file mode 100644 index 0000000000..f6aec86d31 --- /dev/null +++ b/packages/lib/WebAppURL.ts @@ -0,0 +1,8 @@ +import { WEBAPP_URL } from "@calcom/lib/constants"; + +/** This class extends the native URL and uses WEBAPP_URL as the base URL for creating object URLs */ +export class WebAppURL extends URL { + constructor(path: string | URL) { + super(path, WEBAPP_URL); + } +}