diff --git a/app/(admin)/adminDashboard/page.tsx b/app/(admin)/adminDashboard/page.tsx index 83c287a..df8d6f2 100644 --- a/app/(admin)/adminDashboard/page.tsx +++ b/app/(admin)/adminDashboard/page.tsx @@ -40,7 +40,7 @@ type CrmProject = { custom_mobile_phone_no?: string | null; }; -const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:8000'; +const API = process.env.NEXT_PUBLIC_FASTAPI_URL; // Adjust this to your FastAPI route const START_LOGGING_ENDPOINT = (siteId: string) => diff --git a/app/(admin)/sites/page.tsx b/app/(admin)/sites/page.tsx index 03752fa..3bdca7c 100644 --- a/app/(admin)/sites/page.tsx +++ b/app/(admin)/sites/page.tsx @@ -16,7 +16,7 @@ type CrmProject = { custom_mobile_phone_no?: string | null; }; -const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:8000'; +const API = process.env.NEXT_PUBLIC_FASTAPI_URL; const SitesPage = () => { const [projects, setProjects] = useState([]); diff --git a/app/utils/api.ts b/app/utils/api.ts index 67b9cbf..0133831 100644 --- a/app/utils/api.ts +++ b/app/utils/api.ts @@ -9,12 +9,12 @@ export interface TimeSeriesResponse { generation: TimeSeriesEntry[]; } -const API_BASE_URL = - process.env.FASTAPI_URL ?? "http://127.0.0.1:8000"; +const API_URL = + process.env.NEXT_PUBLIC_FASTAPI_URL ; export const crmapi = { getProjects: async () => { - const res = await fetch(`${API_BASE_URL}/crm/projects`, { + const res = await fetch(`${API_URL}/crm/projects`, { }); if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json(); @@ -28,7 +28,7 @@ export async function fetchPowerTimeseries( ): Promise { // <-- Change here const params = new URLSearchParams({ site, start, end }); - const res = await fetch(`http://localhost:8000/power-timeseries?${params.toString()}`); + const res = await fetch(`${API_URL}/power-timeseries?${params.toString()}`); if (!res.ok) { throw new Error(`Failed to fetch data: ${res.status}`); @@ -54,7 +54,7 @@ export async function fetchForecast( kwp: kwp.toString(), }).toString(); - const res = await fetch(`http://localhost:8000/forecast?${query}`); + const res = await fetch(`${API_URL}/forecast?${query}`); if (!res.ok) throw new Error("Failed to fetch forecast"); return res.json(); @@ -73,7 +73,7 @@ export type MonthlyKPI = { error?: string; }; -const API = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000"; +const API = process.env.NEXT_PUBLIC_FASTAPI_URL; export async function fetchMonthlyKpi(params: { site: string; diff --git a/components/auth/components-auth-login-form.tsx b/components/auth/components-auth-login-form.tsx index 8f9789a..2e40ce7 100644 --- a/components/auth/components-auth-login-form.tsx +++ b/components/auth/components-auth-login-form.tsx @@ -12,7 +12,7 @@ const ComponentsAuthLoginForm = () => { const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const router = useRouter(); - const API = process.env.NEXT_PUBLIC_FASTAPI_URL; // e.g. http://localhost:8000 + const API = process.env.NEXT_PUBLIC_FASTAPI_URL; const submitForm = async (e: React.FormEvent) => { e.preventDefault(); diff --git a/components/dashboards/KPIStatus.tsx b/components/dashboards/KPIStatus.tsx index d2bf736..fa947e0 100644 --- a/components/dashboards/KPIStatus.tsx +++ b/components/dashboards/KPIStatus.tsx @@ -21,6 +21,8 @@ const KPI_Table: React.FC = ({ siteId, month }) => { const [kpiData, setKpiData] = useState(null); const [loading, setLoading] = useState(false); + const API_URL = process.env.NEXT_PUBLIC_FASTAPI_URL; + useEffect(() => { if (!siteId || !month) return; @@ -28,7 +30,7 @@ const KPI_Table: React.FC = ({ siteId, month }) => { setLoading(true); try { const res = await fetch( - `http://localhost:8000/kpi/monthly?site=${siteId}&month=${month}` + `${API_URL}/kpi/monthly?site=${siteId}&month=${month}` ); setKpiData(await res.json()); } catch (err) { diff --git a/components/dashboards/LoggingControl.tsx b/components/dashboards/LoggingControl.tsx index 1303678..412daad 100644 --- a/components/dashboards/LoggingControl.tsx +++ b/components/dashboards/LoggingControl.tsx @@ -11,7 +11,7 @@ interface LoggingControlCardProps { className?: string; } -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:8000'; +const API_URL = process.env.NEXT_PUBLIC_FASTAPI_URL; type FnState = { serial: string; diff --git a/components/dashboards/SiteCard.tsx b/components/dashboards/SiteCard.tsx index ff47cca..95d13a6 100644 --- a/components/dashboards/SiteCard.tsx +++ b/components/dashboards/SiteCard.tsx @@ -26,7 +26,7 @@ interface SiteCardProps { fallbackStatus?: string; // optional backup status if CRM is missing it } -const API = process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:8000'; +const API = process.env.NEXT_PUBLIC_FASTAPI_URL; const SiteCard: React.FC = ({ siteId, className = '', fallbackStatus }) => { const [project, setProject] = useState(null); diff --git a/components/dashboards/SiteStatus.tsx b/components/dashboards/SiteStatus.tsx index 5c1ecf3..d1aec77 100644 --- a/components/dashboards/SiteStatus.tsx +++ b/components/dashboards/SiteStatus.tsx @@ -15,8 +15,7 @@ interface SiteStatusProps { lastSyncTimestamp: string; } -const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000"; -const WS_URL = process.env.NEXT_PUBLIC_WS_URL ?? "ws://localhost:8000/ws"; +const API_URL = process.env.NEXT_PUBLIC_FASTAPI_URL; const SiteStatus = ({ selectedSite, @@ -30,7 +29,7 @@ const SiteStatus = ({ // --- WebSocket to receive MQTT-forwarded messages --- useEffect(() => { - const ws = new WebSocket(WS_URL); + const ws = new WebSocket(`${API_URL}/ws`); ws.onopen = () => console.log("WebSocket connected"); ws.onclose = () => console.log("WebSocket disconnected"); diff --git a/components/layouts/header.tsx b/components/layouts/header.tsx index 19196f8..67414ae 100644 --- a/components/layouts/header.tsx +++ b/components/layouts/header.tsx @@ -26,7 +26,7 @@ export default function Header() { const [user, setUser] = useState(null); const [loadingUser, setLoadingUser] = useState(true); - const API = process.env.NEXT_PUBLIC_FASTAPI_URL || 'http://127.0.0.1:8000'; + const API = process.env.NEXT_PUBLIC_FASTAPI_URL; // highlight active menu useEffect(() => {