Skip to content

Commit 25f7381

Browse files
simiondolhaclaudeanikdhabal
authored
fix: add ensureProtocol helper to handle URLs without protocol (calcom#26667)
* fix(event-types): keep slug in sync with title until manually edited Changed from checking `touchedFields` to `dirtyFields` when deciding whether to sync the slug with the title. This fixes the issue where merely focusing on the slug field would stop the sync, even if the user didn't actually edit it. Now the slug stays in sync with the title until the user actually modifies the slug value. Note: The hardcoded "Slug" label for platform users was preserved from the original code. Localizing it would be a separate enhancement. Fixes calcom#26265 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: add ensureProtocol helper to handle URLs without protocol Some container orchestration tools (like Coolify) strip the protocol from URL environment variables. This causes `new URL()` to throw `ERR_INVALID_URL` because strings like "sub.domain.com" are invalid without a protocol prefix. This fix adds an `ensureProtocol` helper function that: - Returns empty string for null/undefined URLs - Preserves URLs that already have http:// or https:// - Prepends https:// to URLs missing the protocol Applied to WEBAPP_URL, WEBSITE_URL, and CAL_URL env var parsing. Fixes calcom#25774 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Clarify URL protocol handling in comments Updated comment to clarify handling of URLs. * Refactor slug handling in CreateEventTypeForm --------- Co-authored-by: simiondolha <simiondolha@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
1 parent 463987c commit 25f7381

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

packages/lib/constants.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Ensures URL has a protocol prefix. If the URL doesn't start with http:// or https://,
3+
* prepends https:// to make it valid for URL parsing.
4+
* This handles cases where environment variables have their protocol stripped
5+
*/
6+
function ensureProtocol(url: string | undefined): string {
7+
if (!url) return "";
8+
if (url.startsWith("http://") || url.startsWith("https://")) return url;
9+
return `https://${url}`;
10+
}
11+
112
const VERCEL_URL = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : "";
213
const RAILWAY_STATIC_URL = process.env.RAILWAY_STATIC_URL ? `https://${process.env.RAILWAY_STATIC_URL}` : "";
314
const HEROKU_URL = process.env.HEROKU_APP_NAME ? `https://${process.env.HEROKU_APP_NAME}.herokuapp.com` : "";
@@ -10,7 +21,7 @@ const IS_DEV = CALCOM_ENV === "development";
1021
export const SINGLE_ORG_SLUG = process.env.NEXT_PUBLIC_SINGLE_ORG_SLUG;
1122
/** https://app.cal.com */
1223
export const WEBAPP_URL =
13-
process.env.NEXT_PUBLIC_WEBAPP_URL ||
24+
ensureProtocol(process.env.NEXT_PUBLIC_WEBAPP_URL) ||
1425
VERCEL_URL ||
1526
RAILWAY_STATIC_URL ||
1627
HEROKU_URL ||
@@ -23,7 +34,7 @@ export const WEBAPP_URL_FOR_OAUTH = IS_PRODUCTION || IS_DEV ? WEBAPP_URL : "http
2334

2435
/** @deprecated use `WEBAPP_URL` */
2536
export const BASE_URL = WEBAPP_URL;
26-
export const WEBSITE_URL = process.env.NEXT_PUBLIC_WEBSITE_URL || "https://cal.com";
37+
export const WEBSITE_URL = ensureProtocol(process.env.NEXT_PUBLIC_WEBSITE_URL) || "https://cal.com";
2738
export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Cal.com";
2839
export const SUPPORT_MAIL_ADDRESS = process.env.NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS || "help@cal.com";
2940
export const COMPANY_NAME = process.env.NEXT_PUBLIC_COMPANY_NAME || "Cal.com, Inc.";
@@ -38,7 +49,7 @@ export const EMAIL_FROM_NAME = process.env.EMAIL_FROM_NAME || APP_NAME;
3849
// Else use the website url if defined and finally fallback to the webapp url
3950
export const CAL_URL = new URL(WEBAPP_URL).hostname.endsWith(".vercel.app")
4051
? WEBAPP_URL
41-
: process.env.NEXT_PUBLIC_WEBSITE_URL || WEBAPP_URL;
52+
: ensureProtocol(process.env.NEXT_PUBLIC_WEBSITE_URL) || WEBAPP_URL;
4253

4354
export const IS_CALCOM =
4455
WEBAPP_URL &&

0 commit comments

Comments
 (0)