From 18b4f53e264ff882295b593e4e7d768bf355d56d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 28 Jun 2026 11:38:40 +0800 Subject: [PATCH] fix(web): use runtime origin for status-chain fetches --- apps/web/src/components/panels/MonitoringPanel.tsx | 3 ++- apps/web/src/components/panels/TicketsPanel.tsx | 10 ++++++---- apps/web/src/hooks/useIncidentStatusChains.ts | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/web/src/components/panels/MonitoringPanel.tsx b/apps/web/src/components/panels/MonitoringPanel.tsx index 7adfc932..684a0c4c 100644 --- a/apps/web/src/components/panels/MonitoringPanel.tsx +++ b/apps/web/src/components/panels/MonitoringPanel.tsx @@ -24,6 +24,7 @@ import { type AwoooPStatusChain, } from '@/components/awooop/status-chain' import type { IncidentTimelineResponse } from '@/lib/api-client' +import { getRuntimeApiBaseUrl } from '@/lib/runtime-api-base' import { Activity, BookOpenCheck, @@ -79,7 +80,7 @@ type EvidenceTone = 'success' | 'warning' | 'blocked' | 'neutral' const getApiBaseUrl = () => { if (typeof window === 'undefined') return '' - return process.env.NEXT_PUBLIC_API_URL ?? '' + return getRuntimeApiBaseUrl() } async function fetchJson(url: string, signal?: AbortSignal): Promise { diff --git a/apps/web/src/components/panels/TicketsPanel.tsx b/apps/web/src/components/panels/TicketsPanel.tsx index 5bb11669..91c2bbeb 100644 --- a/apps/web/src/components/panels/TicketsPanel.tsx +++ b/apps/web/src/components/panels/TicketsPanel.tsx @@ -27,9 +27,10 @@ import { AwoooPStatusChainPanel, type AwoooPStatusChain, } from '@/components/awooop/status-chain' +import { getRuntimeApiBaseUrl } from '@/lib/runtime-api-base' import { cn } from '@/lib/utils' -const API_BASE = process.env.NEXT_PUBLIC_API_URL ?? '' +const getApiBaseUrl = () => (typeof window === 'undefined' ? '' : getRuntimeApiBaseUrl()) interface Incident { incident_id?: string @@ -369,7 +370,7 @@ export function TicketsPanel() { let cancelled = false setLoading(true) setError(null) - fetchJson(`${API_BASE}/api/v1/incidents`, 12_000) + fetchJson(`${getApiBaseUrl()}/api/v1/incidents`, 12_000) .then((data) => { if (cancelled) return if (!data) { @@ -418,15 +419,16 @@ export function TicketsPanel() { async function loadIncidentTruth() { setDetailLoading(true) setDetailError(null) + const apiBase = getApiBaseUrl() const encodedProjectId = encodeURIComponent(projectId) const encodedIncidentId = encodeURIComponent(targetIncidentId) const [statusChain, incidentTimeline] = await Promise.all([ fetchJson( - `${API_BASE}/api/v1/platform/status-chain?project_id=${encodedProjectId}&incident_id=${encodedIncidentId}`, + `${apiBase}/api/v1/platform/status-chain?project_id=${encodedProjectId}&incident_id=${encodedIncidentId}`, 12_000 ), fetchJson( - `${API_BASE}/api/v1/incidents/${encodedIncidentId}/timeline`, + `${apiBase}/api/v1/incidents/${encodedIncidentId}/timeline`, 12_000 ), ]) diff --git a/apps/web/src/hooks/useIncidentStatusChains.ts b/apps/web/src/hooks/useIncidentStatusChains.ts index a9525783..f2dc838c 100644 --- a/apps/web/src/hooks/useIncidentStatusChains.ts +++ b/apps/web/src/hooks/useIncidentStatusChains.ts @@ -3,7 +3,7 @@ import { useEffect, useMemo, useState } from 'react' import type { AwoooPStatusChain } from '@/components/awooop/status-chain' -import { API_V1_URL } from '@/lib/config' +import { getRuntimeApiV1BaseUrl } from '@/lib/runtime-api-base' interface UseIncidentStatusChainsOptions { incidentIds: string[] @@ -56,7 +56,7 @@ export function useIncidentStatusChains({ const fetchStatusChain = async (incidentId: string): Promise => { const params = new URLSearchParams({ project_id: projectId, incident_id: incidentId }) try { - const response = await fetch(`${API_V1_URL}/platform/status-chain?${params.toString()}`, { + const response = await fetch(`${getRuntimeApiV1BaseUrl()}/platform/status-chain?${params.toString()}`, { cache: 'no-store', signal: controller.signal, })