From c2996cd2f8867e61de3152ac9d2cd0e0d090da36 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Tue, 11 Jul 2023 00:49:33 +0530 Subject: [PATCH] fix: 404 booking pages when org support is enabled locally ## What does this PR do? Fix 404 booking pages when org support is enabled locally ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How should this be tested? - Add localhost:3000 to ALLOWED_HOSTNAMES which is the default recommendation for enabling org support locally. Screenshot 2023-07-10 at 11 04 35 AM - Simply restart the server and visit http://localhost:3000/pro. It will give 404. After this change it would work ## Mandatory Tasks - [x] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected. --- apps/web/test/lib/next-config.test.ts | 7 ++++++- packages/features/ee/organizations/lib/orgDomains.ts | 4 ++++ packages/features/test/orgDomains.test.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/web/test/lib/next-config.test.ts b/apps/web/test/lib/next-config.test.ts index deb8bc0fa3..7938778a0d 100644 --- a/apps/web/test/lib/next-config.test.ts +++ b/apps/web/test/lib/next-config.test.ts @@ -172,9 +172,10 @@ describe("next.config.js - RegExp", () => { }); describe("next.config.js - Org Rewrite", () => { - // RegExp copied from next.config.js const orgHostRegExp = (subdomainRegExp: string) => + // RegExp copied from pagesAndRewritePaths.js orgHostPath. Do make the change there as well. new RegExp(`^(?${subdomainRegExp})\\..*`); + describe("Host matching based on NEXT_PUBLIC_WEBAPP_URL", () => { it("https://app.cal.com", () => { const subdomainRegExp = getSubdomainRegExp("https://app.cal.com"); @@ -186,6 +187,10 @@ describe("next.config.js - Org Rewrite", () => { expect( orgHostRegExp(subdomainRegExp).exec("org.cal.com")?.groups?.orgSlug ).toEqual("org"); + + expect( + orgHostRegExp(subdomainRegExp).exec("localhost:3000") + ).toEqual(null); }); it("app.cal.com", () => { diff --git a/packages/features/ee/organizations/lib/orgDomains.ts b/packages/features/ee/organizations/lib/orgDomains.ts index 2c8da147de..a53d02d782 100644 --- a/packages/features/ee/organizations/lib/orgDomains.ts +++ b/packages/features/ee/organizations/lib/orgDomains.ts @@ -5,6 +5,10 @@ import { ALLOWED_HOSTNAMES, RESERVED_SUBDOMAINS, WEBAPP_URL } from "@calcom/lib/ * @param hostname */ export function getOrgSlug(hostname: string) { + if (!hostname.includes(".")) { + // A no-dot domain can never be org domain. It automatically handles localhost + return null; + } // Find which hostname is being currently used const currentHostname = ALLOWED_HOSTNAMES.find((ahn) => { const url = new URL(WEBAPP_URL); diff --git a/packages/features/test/orgDomains.test.ts b/packages/features/test/orgDomains.test.ts index 2fece9b37d..86c518819b 100644 --- a/packages/features/test/orgDomains.test.ts +++ b/packages/features/test/orgDomains.test.ts @@ -30,6 +30,14 @@ describe("Org Domains Utils", () => { isValidOrgDomain: false, }); }); + + it("should return a non valid org domain for localhost", () => { + setupEnvs(); + expect(orgDomainConfig("localhost:3000")).toEqual({ + currentOrgDomain: null, + isValidOrgDomain: false, + }); + }); }); describe("getOrgSlug", () => {