auth/runtime config, URLs centralizados, parsing/hardening dos hooks/charts

This commit is contained in:
litoral05
2026-06-08 16:32:21 +01:00
parent d6daac97c7
commit 19df30326b
32 changed files with 899 additions and 267 deletions
@@ -4,8 +4,9 @@ import type {
WorkspaceChartPoint,
WorkspaceChartTimeRange,
} from "../../../components/charts/WorkspaceChart";
const BACKEND_URL = "http://localhost:18450";
import { authFetch } from "../../../lib/api/authFetch";
import { getBackendApiUrl } from "../../../lib/api/gatewayConfig";
import { readOptionalJsonResponse } from "../../../lib/api/readJsonResponse";
type HistorianPoint = {
timestamp: string;
@@ -54,16 +55,16 @@ export function useClimateChartSeries(
to: to.toISOString(),
});
const response = await fetch(
`${BACKEND_URL}/api/historian/series?${params.toString()}`,
const response = await authFetch(
getBackendApiUrl(`/api/historian/series?${params.toString()}`),
{ signal: controller.signal },
);
if (!response.ok) {
throw new Error(`Failed to load climate history for ${key}`);
}
const payload = (await response.json()) as HistorianPoint[];
const payload = await readOptionalJsonResponse<HistorianPoint[]>(
response,
`Failed to load climate history for ${key}`,
[],
);
const points = payload
.filter(
@@ -130,4 +131,4 @@ function rangeToMs(range: WorkspaceChartTimeRange) {
case "30d":
return 30 * 24 * 60 * 60 * 1000;
}
}
}