integrated the new logger across the entire API

This commit is contained in:
2025-12-31 21:45:38 -05:00
parent 510d4a13ac
commit 9f895a202d
10 changed files with 670 additions and 125 deletions

View File

@@ -3,22 +3,55 @@ const router = express.Router();
import { Request, Response } from 'express';
import { requireLogin } from '../middleware/auth';
import { logger } from '../services/logging/logger';
// GET /welcome
router.get('/welcome', [requireLogin], async (req: Request, res: Response) => {
const output = await fetch(`${process.env.DOC_HOST}/api/pages/717`, {
headers: {
Authorization: `Token ${process.env.DOC_TOKEN_ID}:${process.env.DOC_TOKEN_SECRET}`,
}
})
const t0 = performance.now(); // optional profiling start
if (output.ok) {
const out = await output.json();
try {
const response = await fetch(`${process.env.DOC_HOST}/api/pages/717`, {
headers: {
Authorization: `Token ${process.env.DOC_TOKEN_ID}:${process.env.DOC_TOKEN_SECRET}`,
},
});
if (!response.ok) {
const text = await response.text();
logger.error('app', 'Failed to fetch welcome page from Bookstack', {
status: response.status,
statusText: response.statusText,
body: text,
userId: req.user?.id,
});
return res.sendStatus(500);
}
const out = await response.json();
res.status(200).json(out.html);
} else {
console.error("Failed to fetch LOA policy from bookstack");
// optional profiling log
const duration = performance.now() - t0;
logger.info(
'profiling',
'GET /welcome completed',
{
userId: req.user?.id,
total_ms: duration,
},
'profiling'
);
} catch (error) {
logger.error('app', 'Error fetching welcome page from Bookstack', {
error: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined,
userId: req.user?.id,
});
res.sendStatus(500);
}
})
});
export const docsRouter = router;