Skip to content

Commit

Permalink
feat(web): fix cloud bridge status (#5904)
Browse files Browse the repository at this point in the history
* feat: fix cloud bridge status

* fix: bridge api
  • Loading branch information
scopsy authored Jul 1, 2024
1 parent 95eb32c commit d3cd760
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps/web/src/studio/hooks/useBridgeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
type BridgeStatus,
} from '../../bridgeApi/bridgeApi.client';
import { useStudioState } from '../StudioStateProvider';
import { api as cloudApi } from '../../api';

function useBridgeAPI() {
const { bridgeURL } = useStudioState();

return useMemo(() => buildBridgeHTTPClient(bridgeURL), [bridgeURL]);
}

const BRIDGE_STATUS_REFRESH_INTERVAL_IN_MS = 3 * 1000;
const BRIDGE_STATUS_REFRESH_INTERVAL_IN_MS = 5 * 1000;

export const useDiscover = (options?: any) => {
const api = useBridgeAPI();
Expand All @@ -29,14 +30,18 @@ export const useDiscover = (options?: any) => {
};

export const useHealthCheck = (options?: any) => {
const api = useBridgeAPI();
const { bridgeURL } = useStudioState();
const bridgeAPI = useBridgeAPI();
const { bridgeURL, isLocalStudio } = useStudioState();

const res = useQuery<BridgeStatus>(
['bridge-health-check', bridgeURL],
async () => {
try {
return await api.healthCheck();
if (isLocalStudio) {
return await bridgeAPI.healthCheck();
} else {
return await cloudApi.get('/v1/bridge/status');
}
} catch (error) {
throw error;
}
Expand Down

0 comments on commit d3cd760

Please sign in to comment.