From dfcb42229481a1c60af560b81c979198278f1385 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Thu, 5 Feb 2026 02:15:59 -0600 Subject: [PATCH] refactor(enterprise): consolidate LICENSE_KEY_URL handling and improve license validation logic - Moved LICENSE_KEY_URL definition to a centralized location for better maintainability. - Updated license validation function to utilize the new LICENSE_KEY_URL import, enhancing clarity and consistency in API calls. --- apps/dokploy/server/utils/enterprise.ts | 4 +--- packages/server/src/utils/crons/enterprise.ts | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/dokploy/server/utils/enterprise.ts b/apps/dokploy/server/utils/enterprise.ts index 625a7d00f..d433bd9d0 100644 --- a/apps/dokploy/server/utils/enterprise.ts +++ b/apps/dokploy/server/utils/enterprise.ts @@ -1,6 +1,4 @@ -import { getPublicIpWithFallback } from "@dokploy/server"; - -const LICENSE_KEY_URL = process.env.LICENSE_KEY_URL || "http://localhost:4002"; +import { getPublicIpWithFallback, LICENSE_KEY_URL } from "@dokploy/server"; export const validateLicenseKey = async (licenseKey: string) => { try { diff --git a/packages/server/src/utils/crons/enterprise.ts b/packages/server/src/utils/crons/enterprise.ts index 4fded2e7a..059a8b775 100644 --- a/packages/server/src/utils/crons/enterprise.ts +++ b/packages/server/src/utils/crons/enterprise.ts @@ -4,6 +4,11 @@ import { scheduleJob } from "node-schedule"; import { db } from "../../db/index"; import { user as userSchema } from "../../db/schema/user"; +export const LICENSE_KEY_URL = + process.env.NODE_ENV === "development" + ? "http://localhost:4002" + : "https://api-license-key.dokploy.com"; + export const initEnterpriseBackupCronJobs = async () => { scheduleJob("enterprise-check", "0 0 */3 * *", async () => { const users = await db.query.user.findMany({ @@ -39,16 +44,13 @@ export const initEnterpriseBackupCronJobs = async () => { export const validateLicenseKey = async (licenseKey: string) => { try { const ip = await getPublicIpWithFallback(); - const result = await fetch( - `${process.env.LICENSE_KEY_URL || "http://localhost:4002"}/licenses/validate`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ licenseKey, ip }), + const result = await fetch(`${LICENSE_KEY_URL}/licenses/validate`, { + method: "POST", + headers: { + "Content-Type": "application/json", }, - ); + body: JSON.stringify({ licenseKey, ip }), + }); if (!result.ok) { const errorData = await result.json().catch(() => ({}));