Fix 404 calling utilities internal API — route through nginx slug prefix

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 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-28 14:48:12 +00:00
parent 203639af78
commit 0afecc2e24

View file

@ -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}`)