Skip to content

Commit

Permalink
refactor: use req.originalUrl for simpler logging
Browse files Browse the repository at this point in the history
  • Loading branch information
rackstar committed Jan 7, 2025
1 parent 7b4a406 commit a139d24
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/routes/middleware.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
const { inspect } = require('node:util');

/**
* Request Logger Middleware
*
* Logs incoming requests with method, URL, params, and query.
* Logs incoming requests with method and full URL including query parameters.
*
* @param {import('express').Request} req - The Express request object
* @param {import('express').Response} res - The Express response object
* @param {Function} next - The next middleware function
*/
const requestLogger = (req, res, next) => {
const params = Object.keys(req.params).length ? `\nparams: ${inspect(req.params, { depth: null })}` : '';
const query = Object.keys(req.query).length ? `\nquery: ${inspect(req.query, { depth: null })}` : '';

console.info(`${req.method} ${req.baseUrl}${req.route?.path || req.path}${params}${query}`);
console.info(`${req.method} ${req.originalUrl}`);
next();
};

Expand Down

0 comments on commit a139d24

Please sign in to comment.