Skip to content

Commit

Permalink
feat: log ip address on error
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeht committed Jul 4, 2022
1 parent 517cb33 commit d4c61be
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"pinia": "^2.0.14",
"pino": "^8.1.0",
"pino-pretty": "^8.1.0",
"request-ip": "^3.0.2",
"shelljs": "^0.8.5",
"supertest": "^6.2.3",
"typed.js": "^2.0.12",
Expand Down
4 changes: 3 additions & 1 deletion src/apps/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { env } from '../config/env.js';
import Chad from '../libs/chad.js';
import logger from '../libs/logger.js';
import { red } from '../utils/rainbow-log.js';
import requestIp from 'request-ip';

/**
* It returns a 200 status code with a JSON object containing a message
Expand Down Expand Up @@ -55,7 +56,8 @@ export function notFoundHandler(req, res, next) {
* @param next - This is a function that will be called when the middleware is done.
*/
export function errorHandler(err, req, res, next) {
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
// const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
const ip = requestIp.getClientIp(req);
logger.error(err);
Chad.flex(`${ip}:${err.msg}`, err.stack);

Expand Down

0 comments on commit d4c61be

Please sign in to comment.