diff --git a/frontend/src/components/ocme/CycleCountLog.tsx b/frontend/src/components/ocme/CycleCountLog.tsx index 9b9e81e..3b123a7 100644 --- a/frontend/src/components/ocme/CycleCountLog.tsx +++ b/frontend/src/components/ocme/CycleCountLog.tsx @@ -1,46 +1,49 @@ -//import {useEffect, useState} from "react"; -import {LstCard} from "../extendedUI/LstCard"; -import {CardContent, CardHeader} from "../ui/card"; -import {Skeleton} from "../ui/skeleton"; -import {Button} from "../ui/button"; -import {toast} from "sonner"; +// //import {useEffect, useState} from "react"; +// import {LstCard} from "../extendedUI/LstCard"; +// import {CardContent, CardHeader} from "../ui/card"; +// import {Skeleton} from "../ui/skeleton"; +// import {Button} from "../ui/button"; +// import {toast} from "sonner"; +// import {useEffect} from "react"; -export default function CycleCountLog() { - //const [logs, setLogs] = useState([]); - //const [streaming, setStreaming] = useState(false); // Track if streaming is active +// export default function CycleCountLog() { +// //const [logs, setLogs] = useState([]); +// //const [streaming, setStreaming] = useState(false); // Track if streaming is active - // useEffect(() => { - // // Start streaming when the button is clicked - // let es; +// useEffect(() => { +// // Start streaming when the button is clicked +// let es; - // es = new EventSource("http://localhost:4000/api/logger/logs/stream?service=ocme-count&level=info"); - // es.onopen = () => console.log(">>> Connection opened!"); - // es.onerror = (e) => console.log("ERROR!", e); - // es.onmessage = (e) => { - // console.log(">>>", JSON.stringify(e)); - // }; +// const url = `http://localhost:4000/api/log`; - // return () => es.close(); - // }, []); // Effect runs when `streaming` state changes +// es = new EventSource(url, {withCredentials: true}); +// es.onopen = () => console.log(">>> Connection opened!"); +// es.onerror = (e) => console.log("ERROR!", e); +// es.onmessage = (e) => { +// console.log(">>>", JSON.stringify(e)); +// }; - // const handleStartStreaming = () => { - // setStreaming(true); // Start streaming when button is clicked - // }; - return ( - - - Cycle Count logs - - - {Array(10) - .fill(0) - .map((_, i) => ( -
- -
- ))} -
- -
- ); -} +// return () => es.close(); +// }, []); + +// // const handleStartStreaming = () => { +// // setStreaming(true); // Start streaming when button is clicked +// // }; +// return ( +// +// +// Cycle Count logs +// +// +// {Array(10) +// .fill(0) +// .map((_, i) => ( +//
+// +//
+// ))} +//
+// +//
+// ); +// } diff --git a/server/services/logger/controller/streamLogs.ts b/server/services/logger/controller/streamLogs.ts index 0d8f6e8..2217fed 100644 --- a/server/services/logger/controller/streamLogs.ts +++ b/server/services/logger/controller/streamLogs.ts @@ -1,7 +1,7 @@ import type {Context} from "hono"; import {db} from "../../../../database/dbclient.js"; import {and, eq, gt} from "drizzle-orm"; -import {streamSSE} from "hono/streaming"; +import {streamSSE, streamText} from "hono/streaming"; import {logs} from "../../../../database/schema/logs.js"; export async function streamLogs(c: Context) { diff --git a/server/services/logger/routes/streamLogs.ts b/server/services/logger/routes/streamLogs.ts index 95a54d2..34e2b6c 100644 --- a/server/services/logger/routes/streamLogs.ts +++ b/server/services/logger/routes/streamLogs.ts @@ -29,6 +29,11 @@ app.openapi( }), async (c) => { apiHit(c, {endpoint: `api/logger/logs`}); + c.header("Access-Control-Allow-Origin", "*"); // Or restrict to a specific origin + c.header("Access-Control-Allow-Headers", "Content-Type"); + c.header("Content-Type", "text/event-stream"); + c.header("Cache-Control", "no-cache"); + c.header("Connection", "keep-alive"); return streamLogs(c); } );