test(streaming logs): more test but failed again
This commit is contained in:
@@ -1,19 +1,22 @@
|
|||||||
//import {useEffect, useState} from "react";
|
// //import {useEffect, useState} from "react";
|
||||||
import {LstCard} from "../extendedUI/LstCard";
|
// import {LstCard} from "../extendedUI/LstCard";
|
||||||
import {CardContent, CardHeader} from "../ui/card";
|
// import {CardContent, CardHeader} from "../ui/card";
|
||||||
import {Skeleton} from "../ui/skeleton";
|
// import {Skeleton} from "../ui/skeleton";
|
||||||
import {Button} from "../ui/button";
|
// import {Button} from "../ui/button";
|
||||||
import {toast} from "sonner";
|
// import {toast} from "sonner";
|
||||||
|
// import {useEffect} from "react";
|
||||||
|
|
||||||
export default function CycleCountLog() {
|
// export default function CycleCountLog() {
|
||||||
//const [logs, setLogs] = useState([]);
|
// //const [logs, setLogs] = useState([]);
|
||||||
//const [streaming, setStreaming] = useState(false); // Track if streaming is active
|
// //const [streaming, setStreaming] = useState(false); // Track if streaming is active
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// // Start streaming when the button is clicked
|
// // Start streaming when the button is clicked
|
||||||
// let es;
|
// let es;
|
||||||
|
|
||||||
// es = new EventSource("http://localhost:4000/api/logger/logs/stream?service=ocme-count&level=info");
|
// const url = `http://localhost:4000/api/log`;
|
||||||
|
|
||||||
|
// es = new EventSource(url, {withCredentials: true});
|
||||||
// es.onopen = () => console.log(">>> Connection opened!");
|
// es.onopen = () => console.log(">>> Connection opened!");
|
||||||
// es.onerror = (e) => console.log("ERROR!", e);
|
// es.onerror = (e) => console.log("ERROR!", e);
|
||||||
// es.onmessage = (e) => {
|
// es.onmessage = (e) => {
|
||||||
@@ -21,26 +24,26 @@ export default function CycleCountLog() {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
// return () => es.close();
|
// return () => es.close();
|
||||||
// }, []); // Effect runs when `streaming` state changes
|
// }, []);
|
||||||
|
|
||||||
// const handleStartStreaming = () => {
|
// // const handleStartStreaming = () => {
|
||||||
// setStreaming(true); // Start streaming when button is clicked
|
// // setStreaming(true); // Start streaming when button is clicked
|
||||||
// };
|
// // };
|
||||||
return (
|
// return (
|
||||||
<LstCard className="w-48">
|
// <LstCard className="w-48">
|
||||||
<CardHeader className="flex justify-center">
|
// <CardHeader className="flex justify-center">
|
||||||
<span>Cycle Count logs</span>
|
// <span>Cycle Count logs</span>
|
||||||
</CardHeader>
|
// </CardHeader>
|
||||||
<CardContent>
|
// <CardContent>
|
||||||
{Array(10)
|
// {Array(10)
|
||||||
.fill(0)
|
// .fill(0)
|
||||||
.map((_, i) => (
|
// .map((_, i) => (
|
||||||
<div key={i}>
|
// <div key={i}>
|
||||||
<Skeleton className="m-2 h-4" />
|
// <Skeleton className="m-2 h-4" />
|
||||||
</div>
|
// </div>
|
||||||
))}
|
// ))}
|
||||||
</CardContent>
|
// </CardContent>
|
||||||
<Button onClick={() => toast.success("SOmething")}>Start Stream</Button>
|
// <Button onClick={() => toast.success("SOmething")}>Start Stream</Button>
|
||||||
</LstCard>
|
// </LstCard>
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type {Context} from "hono";
|
import type {Context} from "hono";
|
||||||
import {db} from "../../../../database/dbclient.js";
|
import {db} from "../../../../database/dbclient.js";
|
||||||
import {and, eq, gt} from "drizzle-orm";
|
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";
|
import {logs} from "../../../../database/schema/logs.js";
|
||||||
|
|
||||||
export async function streamLogs(c: Context) {
|
export async function streamLogs(c: Context) {
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ app.openapi(
|
|||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
apiHit(c, {endpoint: `api/logger/logs`});
|
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);
|
return streamLogs(c);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user