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.
This commit is contained in:
Mauricio Siu
2026-02-05 02:15:59 -06:00
parent 47470e2343
commit dfcb422294
2 changed files with 12 additions and 12 deletions

View File

@@ -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 {

View File

@@ -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(() => ({}));