fix(prediction): 시뮬레이션 API를 localhost 대신 api 인스턴스 사용

fetch('http://localhost:3001/...') → api.post('/simulation/run', ...)
배포 환경에서 CORS loopback 차단 문제 해결

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
htlee 2026-03-01 01:31:58 +09:00
부모 bf16762dab
커밋 08b8f16001

파일 보기

@ -14,6 +14,7 @@ import type { BacktrackPhase, BacktrackVessel, BacktrackConditions, ReplayShip,
import { TOTAL_REPLAY_FRAMES } from '@common/types/backtrack'
import { fetchBacktrackByAcdnt, createBacktrack, fetchPredictionDetail } from '../services/predictionApi'
import type { PredictionDetail } from '../services/predictionApi'
import { api } from '@common/services/api'
export type PredictionModel = 'KOSPS' | 'POSEIDON' | 'OpenDrift'
// eslint-disable-next-line react-refresh/only-export-components
@ -259,27 +260,16 @@ export function OilSpillView() {
const models = Array.from(selectedModels)
const results = await Promise.all(
models.map(async (model) => {
const response = await fetch('http://localhost:3001/api/simulation/run', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model,
lat: incidentCoord.lat,
lon: incidentCoord.lon,
duration_hours: predictionTime,
oil_type: oilType,
spill_amount: spillAmount,
spill_type: spillType
})
const { data } = await api.post<{ trajectory: Array<{ lat: number; lon: number; time: number; particle?: number }> }>('/simulation/run', {
model,
lat: incidentCoord.lat,
lon: incidentCoord.lon,
duration_hours: predictionTime,
oil_type: oilType,
spill_amount: spillAmount,
spill_type: spillType,
})
if (!response.ok) {
throw new Error(`API 오류 (${model}): ${response.status}`)
}
const data = await response.json()
return (data.trajectory as Array<{ lat: number; lon: number; time: number; particle?: number }>)
.map(p => ({ ...p, model }))
return data.trajectory.map(p => ({ ...p, model }))
})
)