mirror of
https://github.com/CyberL1/dlinux-dashboard.git
synced 2025-01-21 17:09:19 -05:00
fix(server): container stats sending
This commit is contained in:
parent
63ae224084
commit
f4161b4f47
@ -3,8 +3,27 @@ import { getContainer } from "#src/utils/containers.ts";
|
||||
import type { FastifyInstance, FastifyRequest } from "fastify";
|
||||
|
||||
export default (fastify: FastifyInstance) => {
|
||||
fastify.get("/", (req: FastifyRequest<{ Params: Container }>) => {
|
||||
const container = getContainer(req.params.id);
|
||||
return container.stats();
|
||||
});
|
||||
fastify.get(
|
||||
"/",
|
||||
async (req: FastifyRequest<{ Params: Container }>, reply) => {
|
||||
const container = getContainer(req.params.id);
|
||||
|
||||
reply.header("Content-Type", "text/event-stream");
|
||||
reply.header("Cache-Control", "no-cache");
|
||||
reply.header("Connection", "keep-alive");
|
||||
|
||||
const stream = await container.stats({ stream: true });
|
||||
|
||||
if (!stream) {
|
||||
reply.status(500).send("Error fetching stats");
|
||||
return;
|
||||
}
|
||||
stream.on("data", (chunk) => {
|
||||
reply.raw.write(`data: ${chunk.toString()}\n\n`);
|
||||
});
|
||||
|
||||
stream.on("end", () => reply.raw.end());
|
||||
return stream;
|
||||
},
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user