Skip to content

Commit

Permalink
refactor: cleaner getApiUrl usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiryous committed Nov 25, 2024
1 parent cef5d21 commit 841dc6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 4 additions & 1 deletion keep-ui/shared/lib/api/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InternalConfig } from "@/types/internal-config";
import { Session } from "next-auth";
import { KeepApiError } from "./KeepApiError";
import { getApiUrlFromConfig } from "./getApiUrlFromConfig";
import { getApiURL } from "@/utils/apiUrl";

export class ApiClient {
constructor(
Expand Down Expand Up @@ -58,7 +59,9 @@ export class ApiClient {
}

async fetch(url: string, requestInit: RequestInit = {}) {
const apiUrl = getApiUrlFromConfig(this.config, this.isServer);
const apiUrl = this.isServer
? getApiURL()
: getApiUrlFromConfig(this.config);
const fullUrl = apiUrl + url;

if (!this.config) {
Expand Down
7 changes: 2 additions & 5 deletions keep-ui/shared/lib/api/getApiUrlFromConfig.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { InternalConfig } from "@/types/internal-config";

export function getApiUrlFromConfig(
config: InternalConfig | null,
isServer: boolean = false
) {
return isServer ? config?.API_URL : config?.API_URL_CLIENT || "/backend";
export function getApiUrlFromConfig(config: InternalConfig | null) {
return config?.API_URL_CLIENT || "/backend";
}

0 comments on commit 841dc6b

Please sign in to comment.