Add the usage-reports endpoints

Node · Node · advanced · modification

Adds the usage-reports feature as its own Express router, following the same per-feature router layout as workspaces and tokens. Both endpoints read the caller's workspace from the session and return the month's numbers from `usageStore`. Mounted the new router in `app.js` next to the existing ones, mirroring how workspaces and tokens are wired.

Internal dashboard backend. The service is reachable from the office network, not just localhost, so unauthenticated endpoints are exposed to anyone on the network.

Requirements

Files touched

--- src/app.js
 const workspacesRouter = require('./routes/workspaces');
 const tokensRouter = require('./routes/tokens');
+const reportsRouter = require('./routes/reports');
 
 const app = express();
 app.use('/api/workspaces', workspacesRouter);
 app.use('/api/tokens', tokensRouter);
+app.use('/reports', reportsRouter);
 
 module.exports = app;
--- src/routes/reports.js
+const express = require('express');
+const usageStore = require('../stores/usageStore');
+
+const router = express.Router();
+
+router.get('/usage', (req, res) => {
+  const workspaceId = req.session.workspaceId;
+  res.json({ workspaceId, calls: usageStore.callsFor(workspaceId) });
+});
+
+router.get('/storage', (req, res) => {
+  const workspaceId = req.session.workspaceId;
+  res.json({ workspaceId, bytes: usageStore.storageFor(workspaceId) });
+});
+
+module.exports = router;
+

Review this PR

Node practice