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:
부모
bf16762dab
커밋
08b8f16001
@ -14,6 +14,7 @@ import type { BacktrackPhase, BacktrackVessel, BacktrackConditions, ReplayShip,
|
|||||||
import { TOTAL_REPLAY_FRAMES } from '@common/types/backtrack'
|
import { TOTAL_REPLAY_FRAMES } from '@common/types/backtrack'
|
||||||
import { fetchBacktrackByAcdnt, createBacktrack, fetchPredictionDetail } from '../services/predictionApi'
|
import { fetchBacktrackByAcdnt, createBacktrack, fetchPredictionDetail } from '../services/predictionApi'
|
||||||
import type { PredictionDetail } from '../services/predictionApi'
|
import type { PredictionDetail } from '../services/predictionApi'
|
||||||
|
import { api } from '@common/services/api'
|
||||||
|
|
||||||
export type PredictionModel = 'KOSPS' | 'POSEIDON' | 'OpenDrift'
|
export type PredictionModel = 'KOSPS' | 'POSEIDON' | 'OpenDrift'
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
@ -259,27 +260,16 @@ export function OilSpillView() {
|
|||||||
const models = Array.from(selectedModels)
|
const models = Array.from(selectedModels)
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
models.map(async (model) => {
|
models.map(async (model) => {
|
||||||
const response = await fetch('http://localhost:3001/api/simulation/run', {
|
const { data } = await api.post<{ trajectory: Array<{ lat: number; lon: number; time: number; particle?: number }> }>('/simulation/run', {
|
||||||
method: 'POST',
|
model,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
lat: incidentCoord.lat,
|
||||||
body: JSON.stringify({
|
lon: incidentCoord.lon,
|
||||||
model,
|
duration_hours: predictionTime,
|
||||||
lat: incidentCoord.lat,
|
oil_type: oilType,
|
||||||
lon: incidentCoord.lon,
|
spill_amount: spillAmount,
|
||||||
duration_hours: predictionTime,
|
spill_type: spillType,
|
||||||
oil_type: oilType,
|
|
||||||
spill_amount: spillAmount,
|
|
||||||
spill_type: spillType
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
return data.trajectory.map(p => ({ ...p, model }))
|
||||||
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 }))
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
불러오는 중...
Reference in New Issue
Block a user