From 0afecc2e24a39415d5bd50b225dc74fe21133325 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Tue, 28 Jul 2026 14:48:12 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20404=20calling=20utilities=20internal=20AP?= =?UTF-8?q?I=20=E2=80=94=20route=20through=20nginx=20slug=20prefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The utilities app's backend isn't published to the host, only its nginx frontend on :3080. Its internal.js routes are mounted at bare /api/internal/... with no slug prefix, so callers must go through the /utilities/api/ nginx location (which strips the prefix and forwards to the backend's /api/... path) rather than hitting /api/internal/... directly — the latter has no matching nginx location and 404s. Co-Authored-By: Claude Sonnet 5 --- backend/src/lib/utilities-client.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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}`)