fix: Timeline — utiliser axios /api relatif au lieu de fetch localhost:8000

Les appels fetch vers http://localhost:8000 ne fonctionnent pas en déploiement
Docker — remplacé par axios avec baseURL='/api' comme le reste de l'app.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-24 18:13:47 +02:00
parent c6178c14d5
commit 37f770a09a

View File

@@ -1,8 +1,9 @@
import { useState, useEffect, useCallback } from 'react'
import { ChevronLeft, ChevronRight, Sparkles, Calendar, Clock, Layers, RefreshCw } from 'lucide-react'
import axios from 'axios'
import clsx from 'clsx'
const API = 'http://localhost:8000'
const api = axios.create({ baseURL: '/api' })
interface MarketEvent {
id: number
@@ -231,42 +232,42 @@ export default function Timeline() {
const fetchDay = useCallback(async (d: string) => {
setLoading(true)
try {
const res = await fetch(`${API}/api/timeline/day/${d}`)
if (res.ok) setCtx(await res.json())
} finally {
const res = await api.get(`/timeline/day/${d}`)
setCtx(res.data)
} catch { /* ignore */ } finally {
setLoading(false)
}
}, [])
const fetchEvents = useCallback(async () => {
const res = await fetch(`${API}/api/timeline/events`)
if (res.ok) setAllEvents(await res.json())
try {
const res = await api.get('/timeline/events')
setAllEvents(res.data)
} catch { /* ignore */ }
}, [])
const bootstrap = useCallback(async () => {
const res = await fetch(`${API}/api/timeline/bootstrap`, { method: 'POST' })
if (res.ok) {
try {
await api.post('/timeline/bootstrap')
setBootstrapped(true)
await fetchEvents()
await fetchDay(refDate)
}
} catch { /* ignore */ }
}, [refDate, fetchDay, fetchEvents])
const generateAI = useCallback(async () => {
setGenerating(true)
try {
const res = await fetch(`${API}/api/timeline/generate/${refDate}`, { method: 'POST' })
if (res.ok) {
const data = await res.json()
setCtx(prev => prev ? {
...prev,
long_commentary: data.long_commentary,
medium_commentary: data.medium_commentary,
short_commentary: data.short_commentary,
has_commentary: true,
} : prev)
}
} finally {
const res = await api.post(`/timeline/generate/${refDate}`)
const data = res.data
setCtx(prev => prev ? {
...prev,
long_commentary: data.long_commentary,
medium_commentary: data.medium_commentary,
short_commentary: data.short_commentary,
has_commentary: true,
} : prev)
} catch { /* ignore */ } finally {
setGenerating(false)
}
}, [refDate])