41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
// an external way to creating logs
|
|
//@ts-nocheck
|
|
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
|
import {apiHit} from "../../../globalUtils/apiHits.js";
|
|
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
|
import {createLog} from "../logger.js";
|
|
import {getLogs} from "../controller/getLogs.js";
|
|
import {streamLogs} from "../controller/streamLogs.js";
|
|
import {streamSSE} from "hono/streaming";
|
|
|
|
const app = new OpenAPIHono({strict: false});
|
|
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["server:logger"],
|
|
summary: "Streams the logs to the frontend.",
|
|
method: "get",
|
|
path: "/logs/stream",
|
|
description: "This should only be used on the event you need to monitor logs.",
|
|
|
|
responses: {
|
|
200: {
|
|
content: {
|
|
"application/json": {schema: z.object({message: z.string().optional()})},
|
|
},
|
|
description: "Response message",
|
|
},
|
|
},
|
|
}),
|
|
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);
|
|
}
|
|
);
|
|
export default app;
|