26 lines
715 B
TypeScript
26 lines
715 B
TypeScript
import { observable } from "@trpc/server/observable";
|
|
|
|
import { logger } from "@homarr/log";
|
|
import type { LoggerMessage } from "@homarr/redis";
|
|
import { loggingChannel } from "@homarr/redis";
|
|
|
|
import { createTRPCRouter, publicProcedure } from "../trpc";
|
|
|
|
export const logRouter = createTRPCRouter({
|
|
subscribe: publicProcedure.subscription(() => {
|
|
return observable<LoggerMessage>((emit) => {
|
|
let isConnectionClosed = false;
|
|
|
|
loggingChannel.subscribe((data) => {
|
|
if (isConnectionClosed) return;
|
|
emit.next(data);
|
|
});
|
|
logger.info("A tRPC client has connected to the logging procedure");
|
|
|
|
return () => {
|
|
isConnectionClosed = true;
|
|
};
|
|
});
|
|
}),
|
|
});
|