diff --git a/backend/src/lib/utilities-client.js b/backend/src/lib/utilities-client.js index 3357c528..6edb09cb 100644 --- a/backend/src/lib/utilities-client.js +++ b/backend/src/lib/utilities-client.js @@ -3,13 +3,19 @@ // routes/directors-forecast.js and routes/weekly-actual.js (X-API-Key header, // base URL + key from the app_settings table — set via Settings UI — with // env vars as a fallback, throw on non-2xx). +// +// The base URL points at the utilities app's nginx frontend (its backend +// isn't published to the host), so requests must go through the +// `/utilities/api/` proxy location — nginx strips that prefix and forwards +// to the backend's bare `/api/internal/...` routes. Calling `/api/internal/...` +// directly 404s since nginx has no location for un-prefixed paths. import { getSetting } from '../db.js' async function utilFetch(path) { const apiKey = await getSetting('utilities_api_key') || process.env.UTILITIES_API_KEY const baseUrl = await getSetting('utilities_url') || process.env.UTILITIES_URL || 'http://10.10.10.127:3080' if (!apiKey) throw new Error('UTILITIES_API_KEY not configured') - const res = await fetch(`${baseUrl}${path}`, { + const res = await fetch(`${baseUrl}/utilities${path}`, { headers: { 'X-API-Key': apiKey }, }) if (!res.ok) throw new Error(`Utilities API ${res.status} — ${path}`)