diff --git a/src/services/server.ts b/src/services/server.ts index 8662a44..50c1dc2 100644 --- a/src/services/server.ts +++ b/src/services/server.ts @@ -88,18 +88,31 @@ export async function startUIServer( }); app.get("/api/history", async (req, res) => { - const { searchParams } = new URL(req.url); - const id = searchParams.get("id"); - const url = `${apiConfig.url}/history?id=${id}`; + try { + console.log("GET /api/history"); - const response = await fetch(url, { - headers: { - Authorization: `Bearer ${apiConfig.key}`, - }, - }); + const id = req.query.id; + if (!id) { + throw new Error("No history id on request."); + } + const url = `${apiConfig.url}/history?id=${id}`; + + console.log(url); + console.log(apiConfig.key); + + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${apiConfig.key}`, + }, + }); + + const result = await response.json(); + console.log(result); - const result = await response.json(); - res.json(result); + res.json(result); + } catch (err) { + res.status(500).json({ error: `Failed to fetch chat history: ${err}` }); + } }); // Serve index.html for all routes