Skip to content

Commit fbdcb83

Browse files
authored
Merge branch 'main' into update/torch-291
2 parents 21dca29 + 632a2bb commit fbdcb83

4 files changed

Lines changed: 45 additions & 27 deletions

File tree

src/renderer/App.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,22 @@ function AppContent({
222222
const INITIAL_LOGS_DRAWER_HEIGHT = 200; // Default height for logs drawer when first opened
223223

224224
export default function App() {
225-
// Normalize TL_API_URL - ensure it's either a valid URL or empty string
225+
// Normalize TL_API_URL - ensure it's either a valid URL or default to same host as frontend
226226
const initialApiUrl = (() => {
227227
const envUrl = process.env?.TL_API_URL;
228-
// If undefined, null, or the string "default", use empty string
228+
// If undefined, null, or the string "default", use same host as frontend with API port
229229
if (!envUrl || envUrl === 'default' || envUrl.trim() === '') {
230-
return '';
230+
// Use the same protocol and hostname as the frontend, but with API port 8338
231+
const protocol = window.location.protocol;
232+
const hostname = window.location.hostname;
233+
return `${protocol}//${hostname}:8338/`;
231234
}
232-
return envUrl;
235+
// Ensure the URL has a trailing slash
236+
let url = envUrl.trim();
237+
if (!url.endsWith('/')) {
238+
url = url + '/';
239+
}
240+
return url;
233241
})();
234242

235243
const [connection, setConnection] = useState(initialApiUrl);

src/renderer/components/Login/LoginPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export default function LoginPage() {
135135
const envUrl = process.env.TL_API_URL;
136136
let apiUrl =
137137
!envUrl || envUrl === 'default' || envUrl.trim() === ''
138-
? 'http://localhost:8338'
138+
? `${window.location.protocol}//${window.location.hostname}:8338`
139139
: envUrl;
140140
apiUrl = apiUrl.replace(/\/$/, '');
141141
const url = `${apiUrl}/auth/verify`;

src/renderer/lib/api-client/functions.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export async function downloadModelFromGallery(
8989
export async function activeModels() {
9090
let response;
9191
try {
92-
response = await authenticatedFetch(`${API_URL()}v1/models`);
92+
// Pass just the path - fetchWithAuth will handle prepending the base URL
93+
response = await authenticatedFetch('v1/models');
9394
// console.log('response ok?' + response.ok);
9495
const result = await response.json();
9596
return result;
@@ -104,7 +105,8 @@ export async function activeModels() {
104105
export async function apiHealthz() {
105106
let response;
106107
try {
107-
response = await authenticatedFetch(`${API_URL()}healthz`);
108+
// Pass just the path - fetchWithAuth will handle prepending the base URL
109+
response = await authenticatedFetch('healthz');
108110
// console.log('response ok?' + response.ok);
109111
const result = await response.json();
110112
return result;
@@ -118,7 +120,8 @@ export async function controllerHealthz() {
118120
let response;
119121
try {
120122
// For now we hard code the worker to the default FastChat API port of 21002
121-
response = await authenticatedFetch(API_URL() + 'v1/models', {
123+
// Pass just the path - fetchWithAuth will handle prepending the base URL
124+
response = await authenticatedFetch('v1/models', {
122125
method: 'GET',
123126
});
124127
if (response.ok) {
@@ -135,7 +138,8 @@ export async function controllerHealthz() {
135138
export async function localaiHealthz() {
136139
let response;
137140
try {
138-
response = await authenticatedFetch(API_URL() + 'v1/models');
141+
// Pass just the path - fetchWithAuth will handle prepending the base URL
142+
response = await authenticatedFetch('v1/models');
139143
// console.log('response ok?' + response.ok);
140144
const result = await response.json();
141145
return result;
@@ -148,7 +152,8 @@ export async function localaiHealthz() {
148152
export async function getComputerInfo() {
149153
let response;
150154
try {
151-
response = await authenticatedFetch(API_URL() + 'server/info');
155+
// Pass just the path - fetchWithAuth will handle prepending the base URL
156+
response = await authenticatedFetch('server/info');
152157
// console.log('response ok?' + response.ok);
153158
const result = await response.json();
154159
return result;
@@ -181,21 +186,9 @@ export async function activateWorker(
181186
const paramsJSON = JSON.stringify(parameters);
182187

183188
try {
184-
response = await authenticatedFetch(
185-
API_URL() +
186-
'server/worker_start?model_name=' +
187-
model +
188-
'&adaptor=' +
189-
adaptorName +
190-
'&model_architecture=' +
191-
modelArchitecture +
192-
'&engine=' +
193-
engine +
194-
'&experiment_id=' +
195-
experimentId +
196-
'&parameters=' +
197-
paramsJSON,
198-
);
189+
// Pass just the path with query params - fetchWithAuth will handle prepending the base URL
190+
const queryString = `server/worker_start?model_name=${model}&adaptor=${adaptorName}&model_architecture=${modelArchitecture}&engine=${engine}&experiment_id=${experimentId}&parameters=${paramsJSON}`;
191+
response = await authenticatedFetch(queryString);
199192
const result = await response.json();
200193
return result;
201194
} catch (error) {
@@ -207,7 +200,8 @@ export async function activateWorker(
207200
export async function killWorker() {
208201
let response;
209202
try {
210-
response = await authenticatedFetch(API_URL() + 'server/worker_stop');
203+
// Pass just the path - fetchWithAuth will handle prepending the base URL
204+
response = await authenticatedFetch('server/worker_stop');
211205
const result = await response.json();
212206
return result;
213207
} catch (error) {

src/renderer/lib/authContext.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,23 @@ export async function fetchWithAuth(url: string, options: RequestInit = {}) {
215215

216216
// Handle cases where url might be partial or full
217217
// Ideally fetchWithAuth is passed a relative path, but we handle both.
218-
const fullUrl = url.startsWith('http') ? url : `${API_URL()}${url}`;
218+
let fullUrl: string;
219+
if (url.startsWith('http')) {
220+
fullUrl = url;
221+
} else {
222+
const baseUrl = API_URL();
223+
if (baseUrl === null) {
224+
// Default to same host as frontend with API port if API_URL is not set
225+
// Ensure URL doesn't start with / (baseUrl already has trailing slash)
226+
const cleanPath = url.startsWith('/') ? url.slice(1) : url;
227+
const protocol = window.location.protocol;
228+
const hostname = window.location.hostname;
229+
fullUrl = `${protocol}//${hostname}:8338/${cleanPath}`;
230+
} else {
231+
// baseUrl already has trailing slash from API_URL()
232+
fullUrl = `${baseUrl}${url}`;
233+
}
234+
}
219235

220236
const headers: Record<string, string> = {
221237
...((options.headers as Record<string, string>) || {}),

0 commit comments

Comments
 (0)