Skip to content

Commit

Permalink
feat: override base api host with env
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Apr 4, 2024
1 parent 5641d8f commit 6c24308
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/renderer/api/cadt/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import initialState from '@/store/slices/app/app.initialstate'; // Ensure this path is correct

const projectsTag = 'projects';
const organizationsTag = 'organizations';
Expand All @@ -10,27 +11,23 @@ const baseQuery = fetchBaseQuery({
});

const baseQueryWithDynamicHost = async (args, api, extraOptions) => {

let modifiedArgs = args;
const state = api.getState();
console.log(state)
const currentHost = state.app.apiHost;

console.log(modifiedArgs, currentHost, api, extraOptions)
// Check if currentHost is equal to the initialState's apiHost
const effectiveHost = (currentHost === initialState.apiHost && import.meta.env.VITE_API_HOST) ? import.meta.env.VITE_API_HOST : currentHost;

// If 'args' is a string, it's assumed to be the URL, so prepend the currentHost
// Modify the URL based on the effectiveHost
if (typeof args === 'string') {
modifiedArgs = `${currentHost}${args}`;
modifiedArgs = `${effectiveHost}${args}`;
} else if (args && typeof args === 'object') {
// If 'args' is an object with a 'url' property, prepend the currentHost to the 'url'
modifiedArgs = {
...args,
url: `${currentHost}${args.url}`,
url: `${effectiveHost}${args.url}`,
};
}

console.log(modifiedArgs, currentHost, api, extraOptions)

return await baseQuery(modifiedArgs, api, extraOptions);
};

Expand Down

0 comments on commit 6c24308

Please sign in to comment.