-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve routing of webui requests (#4645)
Have the webui server act as a reverse proxy and route requests to the orchestrator instead of the frontend directly calling the orchestrator. This will simplify webui setup instead of having to define the `WebUI.Backend` to the orchestrator's public ip with bacalhau serve The configuration `WebUI.Backend` is still available and make accepting endpoints more graceful ### Testing done: Mostly manual testing, but verified the following: 1. Routing of basic http requests 2. Routing of websockets, such as log stream 3. Disconnecting and reconnecting the backend 4. Setting `WebUI.Backend` to the demo network. Doesn't make sense today, but in case in the future we want to spin up the WebUI server in a separate process from the orchestrator
- Loading branch information
Showing
6 changed files
with
91 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,18 @@ | ||
import { client } from './generated' | ||
import { useState, useEffect } from 'react' | ||
|
||
interface Config { | ||
APIEndpoint: string | ||
} | ||
|
||
const DEFAULT_API_URL = 'http://localhost:1234' | ||
|
||
async function fetchConfig(): Promise<Config | null> { | ||
try { | ||
const response = await fetch('/_config') | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch config: ${response.statusText}`) | ||
} | ||
return await response.json() | ||
} catch (error) { | ||
console.warn('Config fetch failed, assuming standalone mode:', error) | ||
return null | ||
} | ||
} | ||
|
||
let apiUrl: string | null = null | ||
|
||
export async function initializeApi(): Promise<string> { | ||
const config = await fetchConfig() | ||
apiUrl = config?.APIEndpoint || DEFAULT_API_URL | ||
|
||
client.setConfig({ baseUrl: apiUrl }) | ||
|
||
console.log('API initialized with URL:', apiUrl) | ||
return apiUrl | ||
export function initializeApi(): void { | ||
client.setConfig({ baseUrl: "" }) | ||
} | ||
|
||
export function useApiInitialization() { | ||
const [isInitialized, setIsInitialized] = useState(false) | ||
|
||
useEffect(() => { | ||
initializeApi().then(() => setIsInitialized(true)) | ||
initializeApi() | ||
setIsInitialized(true) | ||
}, []) | ||
|
||
return isInitialized | ||
} | ||
|
||
export function useApiUrl() { | ||
return apiUrl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters