- If connection fails, ensure Ollama is running and CORS is open:
- OLLAMA_ORIGINS=* ollama serve
+ Leave Server URL empty to route through the app's
+ own server (works automatically with the Docker setup). For local
+ dev, set it to http://localhost:11434 and ensure CORS
+ is open: OLLAMA_ORIGINS=* ollama serve
diff --git a/src/engine/aiGenerator.ts b/src/engine/aiGenerator.ts
index 3cd9d5e..5648ec9 100644
--- a/src/engine/aiGenerator.ts
+++ b/src/engine/aiGenerator.ts
@@ -84,7 +84,10 @@ export async function generateWithAI(
settings: OllamaSettings,
signal?: AbortSignal,
): Promise {
- const url = `${settings.baseUrl.replace(/\/$/, '')}/api/chat`;
+ // Empty baseUrl means "same origin" — nginx proxies /api/ to Ollama internally.
+ // A full URL (e.g. http://localhost:11434) is used as-is for local dev.
+ const base = settings.baseUrl ? settings.baseUrl.replace(/\/$/, '') : '';
+ const url = `${base}/api/chat`;
let res: Response;
try {
@@ -104,7 +107,8 @@ export async function generateWithAI(
});
} catch (err) {
if ((err as Error).name === 'AbortError') throw err;
- throw new Error(`Cannot reach Ollama at ${settings.baseUrl}. Is it running?`);
+ const target = settings.baseUrl || '(same origin /api/)';
+ throw new Error(`Cannot reach Ollama at ${target}. Is it running?`);
}
if (!res.ok) {
@@ -130,7 +134,8 @@ export async function generateWithAI(
// Test connectivity and return available model names
export async function testOllamaConnection(baseUrl: string): Promise {
- const url = `${baseUrl.replace(/\/$/, '')}/api/tags`;
+ const base = baseUrl ? baseUrl.replace(/\/$/, '') : '';
+ const url = `${base}/api/tags`;
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
if (!res.ok) throw new Error(`Ollama responded with ${res.status}`);
const data = await res.json() as { models?: Array<{ name: string }> };
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts
index 2452945..09a8f01 100644
--- a/src/hooks/useSettings.ts
+++ b/src/hooks/useSettings.ts
@@ -8,7 +8,7 @@ export interface OllamaSettings {
const DEFAULTS: OllamaSettings = {
enabled: false,
- baseUrl: 'http://localhost:11434',
+ baseUrl: '', // empty = same-origin proxy (/api/ via nginx); set to http://localhost:11434 for local dev
model: 'llama3.2',
};
--
cgit v1.2.3