fix: add ensureProtocol helper to handle URLs without protocol (#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 #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 #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>
This commit is contained in:
1 file changed
+14
-3
@@ -1,3 +1,14 @@
|
||||
/**
|
||||
* Ensures URL has a protocol prefix. If the URL doesn't start with http:// or https://,
|
||||
* prepends https:// to make it valid for URL parsing.
|
||||
* This handles cases where environment variables have their protocol stripped
|
||||
*/
|
||||
function ensureProtocol(url: string | undefined): string {
|
||||
if (!url) return "";
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) return url;
|
||||
return `https://${url}`;
|
||||
}
|
||||
|
||||
const VERCEL_URL = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : "";
|
||||
const RAILWAY_STATIC_URL = process.env.RAILWAY_STATIC_URL ? `https://${process.env.RAILWAY_STATIC_URL}` : "";
|
||||
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";
|
||||
export const SINGLE_ORG_SLUG = process.env.NEXT_PUBLIC_SINGLE_ORG_SLUG;
|
||||
/** https://app.cal.com */
|
||||
export const WEBAPP_URL =
|
||||
process.env.NEXT_PUBLIC_WEBAPP_URL ||
|
||||
ensureProtocol(process.env.NEXT_PUBLIC_WEBAPP_URL) ||
|
||||
VERCEL_URL ||
|
||||
RAILWAY_STATIC_URL ||
|
||||
HEROKU_URL ||
|
||||
@@ -23,7 +34,7 @@ export const WEBAPP_URL_FOR_OAUTH = IS_PRODUCTION || IS_DEV ? WEBAPP_URL : "http
|
||||
|
||||
/** @deprecated use `WEBAPP_URL` */
|
||||
export const BASE_URL = WEBAPP_URL;
|
||||
export const WEBSITE_URL = process.env.NEXT_PUBLIC_WEBSITE_URL || "https://cal.com";
|
||||
export const WEBSITE_URL = ensureProtocol(process.env.NEXT_PUBLIC_WEBSITE_URL) || "https://cal.com";
|
||||
export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Cal.com";
|
||||
export const SUPPORT_MAIL_ADDRESS = process.env.NEXT_PUBLIC_SUPPORT_MAIL_ADDRESS || "help@cal.com";
|
||||
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;
|
||||
// Else use the website url if defined and finally fallback to the webapp url
|
||||
export const CAL_URL = new URL(WEBAPP_URL).hostname.endsWith(".vercel.app")
|
||||
? WEBAPP_URL
|
||||
: process.env.NEXT_PUBLIC_WEBSITE_URL || WEBAPP_URL;
|
||||
: ensureProtocol(process.env.NEXT_PUBLIC_WEBSITE_URL) || WEBAPP_URL;
|
||||
|
||||
export const IS_CALCOM =
|
||||
WEBAPP_URL &&
|
||||
|
||||
Reference in new issue
Block a user