Skip to content

Scheduling infrastructure for absolutely everyone.

chore: Relying on CALCOM_ENV (#10098)

Leo Giovanettia153f9627df4
diff --git a/apps/api/lib/helpers/verifyApiKey.ts b/apps/api/lib/helpers/verifyApiKey.ts
index 118faef6492..6e4fa43ad4c 100644
--- a/apps/api/lib/helpers/verifyApiKey.ts
+++ b/apps/api/lib/helpers/verifyApiKey.ts
@@ -2,6 +2,7 @@ import type { NextMiddleware } from "next-api-middleware";
import { hashAPIKey } from "@calcom/features/ee/api-keys/lib/apiKeys";
import checkLicense from "@calcom/features/ee/common/server/checkLicense";
+import { IS_PRODUCTION } from "@calcom/lib/constants";
import { isAdminGuard } from "~/lib/utils/isAdmin";
@@ -17,7 +18,7 @@ export const dateNotInPast = function (date: Date) {
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
const { prisma, isCustomPrisma, isAdmin } = req;
const hasValidLicense = await checkLicense(prisma);
- if (!hasValidLicense && process.env.NODE_ENV !== "development")
+ if (!hasValidLicense && IS_PRODUCTION)
return res.status(401).json({ error: "Invalid or missing CALCOM_LICENSE_KEY environment variable" });
// If the user is an admin and using a license key (from customPrisma), skip the apiKey check.
if (isCustomPrisma && isAdmin) {
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index edcf79a2fa8..7572fc66afb 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -25,8 +25,10 @@ if (!process.env.NEXTAUTH_URL && process.env.NEXT_PUBLIC_WEBAPP_URL) {
if (!process.env.NEXT_PUBLIC_WEBSITE_URL) {
process.env.NEXT_PUBLIC_WEBSITE_URL = process.env.NEXT_PUBLIC_WEBAPP_URL;
}
-
-if (process.env.CSP_POLICY === "strict" && process.env.NODE_ENV === "production") {
+if (
+ process.env.CSP_POLICY === "strict" &&
+ (process.env.CALCOM_ENV === "production" || process.env.NODE_ENV === "production")
+) {
throw new Error(
"Strict CSP policy(for style-src) is not yet supported in production. You can experiment with it in Dev Mode"
);
diff --git a/apps/web/pages/_document.tsx b/apps/web/pages/_document.tsx
index 0d2ebc7389b..3d6fdae7365 100644
--- a/apps/web/pages/_document.tsx
+++ b/apps/web/pages/_document.tsx
@@ -3,6 +3,8 @@ import type { DocumentContext, DocumentProps } from "next/document";
import Document, { Head, Html, Main, NextScript } from "next/document";
import { z } from "zod";
+import { IS_PRODUCTION } from "@calcom/lib/constants";
+
import { csp } from "@lib/csp";
type Props = Record<string, unknown> & DocumentProps;
@@ -49,7 +51,7 @@ class MyDocument extends Document<Props> {
<meta name="msapplication-TileColor" content="#ff0000" />
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#f9fafb" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#1C1C1C" />
- {(process.env.NODE_ENV === "development" || process.env.VERCEL_ENV === "preview") && (
+ {(!IS_PRODUCTION || process.env.VERCEL_ENV === "preview") && (
// eslint-disable-next-line @next/next/no-sync-scripts
<script
data-project-id="KjpMrKTnXquJVKfeqmjdTffVPf1a6Unw2LZ58iE4"
diff --git a/apps/web/pages/api/email.ts b/apps/web/pages/api/email.ts
index 830e2547733..ad38519ab2d 100644
--- a/apps/web/pages/api/email.ts
+++ b/apps/web/pages/api/email.ts
@@ -1,10 +1,11 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { renderEmail } from "@calcom/emails";
+import { IS_PRODUCTION } from "@calcom/lib/constants";
import { getTranslation } from "@calcom/lib/server/i18n";
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
- if (process.env.NODE_ENV !== "development") return res.write("Only for development purposes"), res.end();
+ if (IS_PRODUCTION) return res.write("Only for development purposes"), res.end();
const t = await getTranslation("en", "common");
const language = { translate: t, locale: "en" };
diff --git a/apps/web/pages/apps/[slug]/index.tsx b/apps/web/pages/apps/[slug]/index.tsx
index 9a9b478b5d0..02893584709 100644
--- a/apps/web/pages/apps/[slug]/index.tsx
+++ b/apps/web/pages/apps/[slug]/index.tsx
@@ -9,6 +9,7 @@ import { z } from "zod";
import { getAppWithMetadata } from "@calcom/app-store/_appRegistry";
import { getAppAssetFullPath } from "@calcom/app-store/getAppAssetFullPath";
+import { IS_PRODUCTION } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
import type { inferSSRProps } from "@lib/types/inferSSRProps";
@@ -38,7 +39,7 @@ const sourceSchema = z.object({
function SingleAppPage(props: inferSSRProps<typeof getStaticProps>) {
// If it's not production environment, it would be a better idea to inform that the App is disabled.
if (props.isAppDisabled) {
- if (process.env.NODE_ENV !== "production") {
+ if (!IS_PRODUCTION) {
// TODO: Improve disabled App UI. This is just a placeholder.
return (
<div className="p-2">
@@ -123,7 +124,7 @@ export const getStaticProps = async (ctx: GetStaticPropsContext) => {
const isAppAvailableInFileSystem = appMeta;
const isAppDisabled = isAppAvailableInFileSystem && (!appFromDb || !appFromDb.enabled);
- if (process.env.NODE_ENV !== "production" && isAppDisabled) {
+ if (!IS_PRODUCTION && isAppDisabled) {
return {
props: {
isAppDisabled: true as const,
diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts
index 336b6d9761a..7960512c69f 100644
--- a/packages/lib/constants.ts
+++ b/packages/lib/constants.ts
@@ -2,7 +2,8 @@ const VERCEL_URL = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.N
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` : "";
const RENDER_URL = process.env.RENDER_EXTERNAL_URL ? `https://${process.env.RENDER_EXTERNAL_URL}` : "";
-export const IS_PRODUCTION = process.env.NODE_ENV === "production";
+export const CALCOM_ENV = process.env.CALCOM_ENV || process.env.NODE_ENV;
+export const IS_PRODUCTION = CALCOM_ENV === "production";
export const WEBAPP_URL =
process.env.NEXT_PUBLIC_WEBAPP_URL ||
diff --git a/turbo.json b/turbo.json
index c13a17b84bf..5d6eb147dca 100644
--- a/turbo.json
+++ b/turbo.json
@@ -182,6 +182,7 @@
"APP_USER_NAME",
"AUTH_BEARER_TOKEN_VERCEL",
"BUILD_ID",
+ "CALCOM_ENV",
"CALCOM_LICENSE_KEY",
"CALCOM_TELEMETRY_DISABLED",
"CALENDSO_ENCRYPTION_KEY",