diff --git a/server/lib/config.ts b/server/lib/config.ts index f71cfd51..13a1f6a4 100644 --- a/server/lib/config.ts +++ b/server/lib/config.ts @@ -6,7 +6,6 @@ import { eq } from "drizzle-orm"; import { configSchema, readConfigFile } from "./readConfigFile"; import { fromError } from "zod-validation-error"; import { build } from "@server/build"; -import { pullEnv } from "@app/lib/pullEnv"; export class Config { private rawConfig!: z.infer; @@ -150,7 +149,6 @@ export class Config { public async checkSupporterKey() { const [key] = await db.select().from(supporterKey).limit(1); - const env = pullEnv(); if (!key) { return; @@ -160,7 +158,7 @@ export class Config { try { const response = await fetch( - `${env.app.fossorialRemoteAPIBaseUrl}/api/v1/license/validate`, + `https://api.fossorial.io/api/v1/license/validate`, { method: "POST", headers: { diff --git a/server/private/routers/generatedLicense/generateNewLicense.ts b/server/private/routers/generatedLicense/generateNewLicense.ts index dfbaaa89..2c0c4420 100644 --- a/server/private/routers/generatedLicense/generateNewLicense.ts +++ b/server/private/routers/generatedLicense/generateNewLicense.ts @@ -18,13 +18,11 @@ import logger from "@server/logger"; import { response as sendResponse } from "@server/lib/response"; import privateConfig from "#private/lib/config"; import { GenerateNewLicenseResponse } from "@server/routers/generatedLicense/types"; -import { pullEnv } from "@app/lib/pullEnv"; async function createNewLicense(orgId: string, licenseData: any): Promise { try { - const env = pullEnv(); const response = await fetch( - `${env.app.fossorialRemoteAPIBaseUrl}/api/v1/license-internal/enterprise/${orgId}/create`, + `https://api.fossorial.io/api/v1/license-internal/enterprise/${orgId}/create`, { method: "PUT", headers: { diff --git a/server/private/routers/generatedLicense/listGeneratedLicenses.ts b/server/private/routers/generatedLicense/listGeneratedLicenses.ts index 839c8a2c..fb54c763 100644 --- a/server/private/routers/generatedLicense/listGeneratedLicenses.ts +++ b/server/private/routers/generatedLicense/listGeneratedLicenses.ts @@ -21,13 +21,11 @@ import { GeneratedLicenseKey, ListGeneratedLicenseKeysResponse } from "@server/routers/generatedLicense/types"; -import { pullEnv } from "@app/lib/pullEnv"; async function fetchLicenseKeys(orgId: string): Promise { try { - const env = pullEnv(); const response = await fetch( - `${env.app.fossorialRemoteAPIBaseUrl}/api/v1/license-internal/enterprise/${orgId}/list`, + `https://api.fossorial.io/api/v1/license-internal/enterprise/${orgId}/list`, { method: "GET", headers: { diff --git a/server/routers/supporterKey/validateSupporterKey.ts b/server/routers/supporterKey/validateSupporterKey.ts index 82315017..338c920e 100644 --- a/server/routers/supporterKey/validateSupporterKey.ts +++ b/server/routers/supporterKey/validateSupporterKey.ts @@ -5,12 +5,9 @@ import createHttpError from "http-errors"; import logger from "@server/logger"; import { fromError } from "zod-validation-error"; import { response as sendResponse } from "@server/lib/response"; -import { suppressDeprecationWarnings } from "moment"; import { supporterKey } from "@server/db"; import { db } from "@server/db"; -import { eq } from "drizzle-orm"; import config from "@server/lib/config"; -import { pullEnv } from "@app/lib/pullEnv"; const validateSupporterKeySchema = z .object({ @@ -32,7 +29,6 @@ export async function validateSupporterKey( next: NextFunction ): Promise { try { - const env = pullEnv(); const parsedBody = validateSupporterKeySchema.safeParse(req.body); if (!parsedBody.success) { return next( @@ -46,7 +42,7 @@ export async function validateSupporterKey( const { githubUsername, key } = parsedBody.data; const response = await fetch( - `${env.app.fossorialRemoteAPIBaseUrl}/api/v1/license/validate`, + `https://api.fossorial.io/api/v1/license/validate`, { method: "POST", headers: { diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index a75d3abe..14735053 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -51,8 +51,14 @@ export const internal = axios.create({ } }); +const remoteAPIURL = + process.env.NODE_ENV === "development" + ? (process.env.NEXT_PUBLIC_FOSSORIAL_REMOTE_API_URL ?? + "https://api.fossorial.io") + : "https://api.fossorial.io"; + export const remote = axios.create({ - baseURL: `${process.env.NEXT_PUBLIC_FOSSORIAL_REMOTE_API_URL}/api/v1`, + baseURL: `${remoteAPIURL}/api/v1`, timeout: 10000, headers: { "Content-Type": "application/json", diff --git a/src/lib/pullEnv.ts b/src/lib/pullEnv.ts index 7e5a0dc4..7893a8c6 100644 --- a/src/lib/pullEnv.ts +++ b/src/lib/pullEnv.ts @@ -21,11 +21,6 @@ const envSchema = z.object({ .transform((val) => val === "true"), APP_VERSION: z.string(), DASHBOARD_URL: z.string(), - NEXT_PUBLIC_FOSSORIAL_REMOTE_API_URL: z - .string() - .url() - .default("https://api.fossorial.io") - .transform((url) => url.replace(/(.*)\/?$/, "$1")), // Email configuration EMAIL_ENABLED: z @@ -117,8 +112,7 @@ export function pullEnv(): Env { environment: env.ENVIRONMENT, sandbox_mode: env.SANDBOX_MODE, version: env.APP_VERSION, - dashboardUrl: env.DASHBOARD_URL, - fossorialRemoteAPIBaseUrl: env.NEXT_PUBLIC_FOSSORIAL_REMOTE_API_URL + dashboardUrl: env.DASHBOARD_URL }, email: { emailEnabled: env.EMAIL_ENABLED diff --git a/src/lib/types/env.ts b/src/lib/types/env.ts index 64bc8d73..6ebf758a 100644 --- a/src/lib/types/env.ts +++ b/src/lib/types/env.ts @@ -4,7 +4,6 @@ export type Env = { sandbox_mode: boolean; version: string; dashboardUrl: string; - fossorialRemoteAPIBaseUrl: string; }; server: { externalPort: string;