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

<!-- Please delete bullets that are not relevant. -->

- Bug fix (non-breaking change which fixes an issue)

## How should this be tested?

<!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration -->

-  Add localhost:3000 to ALLOWED_HOSTNAMES which is the default recommendation for enabling org support locally.
<img width="1035" alt="Screenshot 2023-07-10 at 11 04 35 AM" src="https://github.com/calcom/cal.com/assets/1780212/7272437b-afae-4073-905b-eafc39f9fafc">
- 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.
This commit is contained in:
Hariom Balhara
2023-07-10 12:19:33 -07:00
committed by GitHub
parent 79944dfed1
commit c2996cd2f8
3 changed files with 18 additions and 1 deletions
+6 -1
View File
@@ -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", () => {
@@ -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);
@@ -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", () => {