23 lines
662 B
JavaScript
23 lines
662 B
JavaScript
import express from 'express';
|
|
import { basicAuthMiddleware } from '../middlewares/auth.js';
|
|
import { getLogPath, readLogs } from '../utils/fileUtils.js';
|
|
|
|
const router = express.Router();
|
|
|
|
// Obtener logs (últimas líneas o nuevas líneas desde un número de línea)
|
|
router.get('/', basicAuthMiddleware, (req, res) => {
|
|
try {
|
|
const logPath = getLogPath();
|
|
const sinceLine = parseInt(req.query.since) || 0;
|
|
const limit = parseInt(req.query.limit) || 500;
|
|
|
|
const result = readLogs(logPath, { sinceLine, limit });
|
|
res.json(result);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
export default router;
|
|
|