fix(web): use runtime origin for status-chain fetches
This commit is contained in:
@@ -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<T>(url: string, signal?: AbortSignal): Promise<T> {
|
||||
|
||||
@@ -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<IncidentListResponse>(`${API_BASE}/api/v1/incidents`, 12_000)
|
||||
fetchJson<IncidentListResponse>(`${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<AwoooPStatusChain>(
|
||||
`${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<IncidentTimelineResponse>(
|
||||
`${API_BASE}/api/v1/incidents/${encodedIncidentId}/timeline`,
|
||||
`${apiBase}/api/v1/incidents/${encodedIncidentId}/timeline`,
|
||||
12_000
|
||||
),
|
||||
])
|
||||
|
||||
@@ -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<AwoooPStatusChain | null> => {
|
||||
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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user