Scheduling infrastructure for absolutely everyone.
chore: Introduce a new class WebAppURL that extends URL (#14982)
Anik Dhabal Babu2ad3592eb39b
diff --git a/apps/web/app/WithEmbedSSR.tsx b/apps/web/app/WithEmbedSSR.tsxindex c19ead200d5..a7d5387425a 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<T extends Record<string, any>>(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.tsxindex 228e6a2c4ad..19a98ee263e 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.tsnew file mode 100644index 00000000000..f6aec86d31d--- /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);+ }+}