fix: route API + Ollama calls through ops-frontend nginx proxy

All /api/ and /ollama/ requests now go through the ops base path
(/ops/api/... and /ops/ollama/...) so Traefik routes them to
ops-frontend nginx, which injects the ERPNext token server-side.
Token is never exposed in the browser.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
louispaulb 2026-03-31 00:00:14 -04:00
parent 2453bc6ef2
commit 26a0077015
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,9 @@
import { authFetch } from './auth'
const OLLAMA_URL = '/ollama/api/generate'
// Use the Vite base path so requests route through ops-frontend nginx
// In production: /ops/ollama/... → Traefik strips /ops → nginx /ollama/ → Ollama
const BASE = import.meta.env.BASE_URL || '/'
const OLLAMA_URL = BASE + 'ollama/api/generate'
const OCR_PROMPT = `You are an invoice/bill OCR assistant. Extract the following fields from this image of a bill or invoice. Return ONLY valid JSON, no markdown, no explanation.
@ -71,7 +74,7 @@ export async function ocrBill (base64Image) {
*/
export async function checkOllamaStatus () {
try {
const res = await authFetch('/ollama/api/tags')
const res = await authFetch(BASE + 'ollama/api/tags')
if (!res.ok) return { online: false, error: 'HTTP ' + res.status }
const data = await res.json()
const models = (data.models || []).map(m => m.name)

View File

@ -1,4 +1,8 @@
export const BASE_URL = ''
// Route API calls through ops-frontend nginx (which injects the ERPNext token)
// In production: /ops/api/... → Traefik strips /ops → nginx proxies to ERPNext with token
// In dev: '' (uses VITE_ERP_TOKEN or devServer proxy)
const viteBase = import.meta.env.BASE_URL || '/'
export const BASE_URL = viteBase === '/' ? '' : viteBase.replace(/\/$/, '')
export const MAPBOX_TOKEN = 'pk.eyJ1IjoidGFyZ29pbnRlcm5ldCIsImEiOiJjbW13Z3lwMXAwdGt1MnVvamsxNWkybzFkIn0.rdYB17XUdfn96czdnnJ6eg'