Enhance logging for unauthorized access and task/tag operations; remove unused debug statement

This commit is contained in:
2025-01-30 22:14:25 +01:00
parent 23a6d9b10f
commit 2a7005f53c
3 changed files with 3 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ const auth = (req, res, next) => {
return next();
} else {
res.status(401).send('Authentication required.');
logger.error('Unauthorized access attempted from IP:', req.ip);
logger.error(`Unauthorized access attempted from IP: ${req.ip}`);
}
};

View File

@@ -52,6 +52,7 @@ router.post('/add-task', auth, async (req, res) => {
- State "TODO" from "TODO" [${currentDateTime}]
:END:
`;
logger.info(`Task added: ${orgFormattedData}`);
}
const filePath = path.join(dataDir, 'tasks.org');
@@ -71,6 +72,7 @@ router.post('/save-tags', auth, async (req, res) => {
try {
await fs.promises.writeFile(filePath, JSON.stringify(tags));
res.send({ message: 'Tags saved successfully!' });
logger.info(`New tags saved: ${tags}`);
} catch (err) {
logger.error('Error saving tags:', err);
res.status(500).send('Error saving tags.');

View File

@@ -4,7 +4,6 @@ const bodyParser = require('body-parser');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const SQLiteStore = require('connect-sqlite3')(session);
const debug = require('debug')('app');
const tasksRouter = require('./routes/tasks');
const authRouter = require('./routes/auth');
const authMiddleware = require('./middleware/auth');
@@ -39,5 +38,4 @@ app.use('/', authMiddleware, tasksRouter);
app.listen(port, () => {
logger.info(`Server running at http://localhost:${port}`);
//debug(`Server running at http://localhost:${port}`);
});