File size: 724 Bytes
03b405b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const express = require("express");
const path = require("node:path");
const { paths } = require("../config/paths");
const { snapshot } = require("../monitoring/metrics");
const { listJobs, listEvents } = require("../queue/jobs");

function createDashboardServer() {
  const app = express();
  app.use(express.static(paths.dashboardPublic));
  app.get("/api/status", async (_req, res) => res.json(await snapshot()));
  app.get("/api/queue", (_req, res) => res.json({ jobs: listJobs(100) }));
  app.get("/api/logs", (_req, res) => res.json({ events: listEvents(200) }));
  app.get("*", (_req, res) => res.sendFile(path.join(paths.dashboardPublic, "index.html")));
  return app;
}

module.exports = { createDashboardServer };