From a153f9627df48268279f96671a8a6aaf13831ecb Mon Sep 17 00:00:00 2001 From: Leo Giovanetti Date: Thu, 10 Aug 2023 13:32:20 -0300 Subject: [PATCH] chore: Relying on CALCOM_ENV (#10098) * Relying on CALCOM_ENV * Restoring unneeded changes * Relyon more on IS_PRODUCTION * Relyon more on IS_PRODUCTION --- apps/api/lib/helpers/verifyApiKey.ts | 3 ++- apps/web/next.config.js | 6 ++++-- apps/web/pages/_document.tsx | 4 +++- apps/web/pages/api/email.ts | 3 ++- apps/web/pages/apps/[slug]/index.tsx | 5 +++-- packages/lib/constants.ts | 3 ++- turbo.json | 1 + 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/api/lib/helpers/verifyApiKey.ts b/apps/api/lib/helpers/verifyApiKey.ts index 118faef649..6e4fa43ad4 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 edcf79a2fa..7572fc66af 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 0d2ebc7389..3d6fdae736 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 & DocumentProps; @@ -49,7 +51,7 @@ class MyDocument extends Document { - {(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