Skip to content

Scheduling infrastructure for absolutely everyone.

fix: 404 booking pages when org support is enabled locally

Hariom Balharac2996cd2f886
diff --git a/apps/web/test/lib/next-config.test.ts b/apps/web/test/lib/next-config.test.ts
index deb8bc0fa3f..7938778a0d4 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(`^(?<orgSlug>${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 2c8da147de3..a53d02d782e 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 2fece9b37d3..86c518819b9 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", () => {