diff --git a/app/ui/app/src/api.ts b/app/ui/app/src/api.ts index 4158bafc..a06e4e00 100644 --- a/app/ui/app/src/api.ts +++ b/app/ui/app/src/api.ts @@ -15,6 +15,7 @@ import { import { parseJsonlFromResponse } from "./util/jsonl-parsing"; import { ollamaClient as ollama } from "./lib/ollama-client"; import type { ModelResponse } from "ollama/browser"; +import { API_BASE } from "./lib/config"; // Extend Model class with utility methods declare module "@/gotypes" { @@ -27,8 +28,6 @@ Model.prototype.isCloud = function (): boolean { return this.model.endsWith("cloud"); }; -const API_BASE = import.meta.env.DEV ? "http://127.0.0.1:3001" : ""; - // Helper function to convert Uint8Array to base64 function uint8ArrayToBase64(uint8Array: Uint8Array): string { const chunkSize = 0x8000; // 32KB chunks to avoid stack overflow diff --git a/app/ui/app/src/lib/config.ts b/app/ui/app/src/lib/config.ts new file mode 100644 index 00000000..c1124396 --- /dev/null +++ b/app/ui/app/src/lib/config.ts @@ -0,0 +1,10 @@ +// API configuration +const DEV_API_URL = "http://127.0.0.1:3001"; + +// Base URL for fetch API calls (can be relative in production) +export const API_BASE = import.meta.env.DEV ? DEV_API_URL : ""; + +// Full host URL for Ollama client (needs full origin in production) +export const OLLAMA_HOST = import.meta.env.DEV + ? DEV_API_URL + : window.location.origin; diff --git a/app/ui/app/src/lib/ollama-client.ts b/app/ui/app/src/lib/ollama-client.ts index 9e931614..50915a0b 100644 --- a/app/ui/app/src/lib/ollama-client.ts +++ b/app/ui/app/src/lib/ollama-client.ts @@ -1,4 +1,5 @@ import { Ollama } from "ollama/browser"; +import { OLLAMA_HOST } from "./config"; let _ollamaClient: Ollama | null = null; @@ -6,7 +7,7 @@ export const ollamaClient = new Proxy({} as Ollama, { get(_target, prop) { if (!_ollamaClient) { _ollamaClient = new Ollama({ - host: window.location.origin, + host: OLLAMA_HOST, }); } const value = _ollamaClient[prop as keyof Ollama];