nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.69k stars 7.63k forks source link

LogMiddleware is written twice each request & response #13007

Closed nikasha89 closed 10 months ago

nikasha89 commented 10 months ago

Is there an existing issue for this?

Current behavior

LogMiddleware is written twice each request & response. You can see a whole description with code here in StackOverFlow issue.

Minimum reproduction code

https://stackoverflow.com/questions/77751486/loggingmiddleware-nestjs-duplicated-log-records

Steps to reproduce

  1. nx serve xdsb
  2. Open swagger docs in the browser.
  3. Do any call to any endpoint,
  4. See the log records at console.

Expected behavior

LogMiddleware is written just 1 time each request & response.

Package

Other package

No response

NestJS version

9.1.6

Packages versions

{
    "name": "sb-wg-apps-api",
    "version": "0.0.6",
    "lockfileVersion": 2,
    "requires": true,
    "packages": {
        "": {
            "name": "sb-wg-apps-api",
            "version": "0.0.6",
            "license": "MIT",
            "dependencies": {
                "@aws-sdk/client-s3": "^3.241.0",
                "@fast-csv/format": "^4.3.5",
                "@golevelup/nestjs-discovery": "^3.0.0",
                "@golevelup/nestjs-rabbitmq": "^3.7.0",
                "@instana/collector": "^2.14.0",
                "@ladjs/country-language": "^1.0.2",
                "@nestjs/axios": "^1.0.1",
                "@nestjs/common": "^9.2.1",
                "@nestjs/core": "^9.2.1",
                "@nestjs/jwt": "^9.0.0",
                "@nestjs/mongoose": "^9.2.0",
                "@nestjs/passport": "^10.0.0",
                "@nestjs/platform-express": "^9.2.1",
                "@nestjs/platform-socket.io": "^9.2.1",
                "@nestjs/serve-static": "^3.0.0",
                "@nestjs/swagger": "^6.1.4",
                "@nestjs/terminus": "^9.1.0",
                "@nestjs/websockets": "^9.2.1",
                "@type-cacheable/core": "^11.0.1",
                "@type-cacheable/ioredis-adapter": "^12.1.0",
                "@types/amqplib": "^0.8.2",
                "@types/simple-oauth2": "^4.1.1",
                "amqplib": "^0.10.0",
                "axios": "1.2.1",
                "axios-retry": "^3.3.1",
                "basic-auth-parser": "^0.0.2-1",
                "cache-manager": "^5.1.4",
                "cache-manager-ioredis": "^2.1.0",
                "class-transformer": "^0.5.1",
                "class-validator": "^0.14.0",
                "dotenv": "^16.0.1",
                "exceljs": "^4.3.0",
                "express": "^4.18.2",
                "express-bearer-token": "^2.4.0",
                "form-data": "^4.0.0",
                "generate-password": "^1.7.0",
                "http-proxy": "^1.18.1",
                "http-proxy-middleware": "^2.0.3",
                "http-status-codes": "^2.2.0",
                "image-size": "^1.0.2",
                "ioredis": "^5.0.6",
                "is-docker": "^3.0.0",
                "json-to-pretty-yaml": "^1.2.2",
                "jwks-rsa": "^3.0.1",
                "kafkajs": "^2.2.3",
                "lodash": "^4.17.21",
                "lru-cache": "^7.12.0",
                "luxon": "^3.0.1",
                "migrate-mongo": "^9.0.0",
                "mime-types": "^2.1.35",
                "minimist": "^1.2.6",
                "moment-timezone": "^0.5.34",
                "mongoose": "^6.3.5",
                "multer": "^1.4.5-lts.1",
                "nest-winston": "^1.6.2",
                "nestjs-asyncapi": "^1.1.0",
                "nestjs-cls": "^3.0.3",
                "object-hash": "^3.0.0",
                "oniyi-ltpa": "^2.1.0",
                "passport": "^0.6.0",
                "passport-jwt": "^4.0.1",
                "pg": "^8.7.3",
                "pg-cursor": "^2.7.3",
                "query-string": "^7.1.1",
                "redlock": "^5.0.0-beta.2",
                "reflect-metadata": "^0.1.13",
                "rxjs": "^7.5.2",
                "simple-oauth2": "^5.0.0",
                "socket.io": "^4.5.1",
                "socket.io-client": "^4.5.1",
                "swagger-ui-express": "^4.4.0",
                "tar": "^6.1.11",
                "tslib": "^2.3.1",
                "uuid": "^9.0.0",
                "web-push": "^3.4.5",
                "winston": "^3.4.0"
            },
            "devDependencies": {
                "@compodoc/compodoc": "^1.1.15",
                "@golevelup/ts-jest": "^0.3.2",
                "@jest-mock/express": "^2.0.1",
                "@nestjs/schematics": "9.0.1",
                "@nestjs/testing": "^9.2.1",
                "@nrwl/cli": "15.7.2",
                "@nrwl/devkit": "15.7.2",
                "@nrwl/eslint-plugin-nx": "15.7.2",
                "@nrwl/jest": "15.7.2",
                "@nrwl/linter": "15.7.2",
                "@nrwl/nest": "15.7.2",
                "@nrwl/node": "15.7.2",
                "@nrwl/workspace": "15.7.2",
                "@nx-tools/nx-container": "^4.0.2",
                "@swc/helpers": "^0.3.17",
                "@twittwer/compodoc": "^1.8.0",
                "@types/amqp-connection-manager": "^3.4.1",
                "@types/boom": "^7.3.2",
                "@types/cache-manager": "^4.0.2",
                "@types/express": "^4.17.13",
                "@types/formdata": "^0.10.1",
                "@types/http-proxy": "^1.17.5",
                "@types/jest": "28.1.3",
                "@types/lodash": "^4.14.178",
                "@types/luxon": "^3.0.0",
                "@types/multer": "^1.4.7",
                "@types/node": "18.7.1",
                "@types/object-hash": "^2.2.1",
                "@types/passport-jwt": "^3.0.9",
                "@types/pg": "^8.6.5",
                "@types/pg-cursor": "^2.7.0",
                "@types/supertest": "^2.0.11",
                "@types/tar": "^6.1.1",
                "@types/web-push": "^3.3.2",
                "@typescript-eslint/eslint-plugin": "5.36.2",
                "@typescript-eslint/parser": "5.36.2",
                "axios-mock-adapter": "^1.21.1",
                "eslint": "8.15.0",
                "eslint-config-prettier": "^8.5.0",
                "flatten-directory": "^1.0.8",
                "husky": "^8.0.1",
                "jest": "28.1.3",
                "jest-each": "28.1.3",
                "jest-environment-jsdom": "28.1.1",
                "jest-junit": "^15.0.0",
                "jest-when": "^3.5.0",
                "json-schema-to-typescript": "^11.0.2",
                "lint-staged": "^13.0.0",
                "mock-express-request": "^0.2.2",
                "mock-express-response": "^0.3.0",
                "mongodb-memory-server": "^8.6.0",
                "nock": "^13.2.9",
                "nx": "15.7.2",
                "nyc": "^15.1.0",
                "organize-imports-cli": "^0.10.0",
                "prettier": "^2.7.1",
                "rimraf": "^4.4.1",
                "sonar-scanner": "^3.1.0",
                "supertest": "^6.2.1",
                "timekeeper": "^2.2.0",
                "ts-jest": "28.0.5",
                "ts-node": "10.9.1",
                "typescript": "4.8.4"
            }
        }
}

Node.js version

18.13.0

In which operating systems have you tested?

Other

I had to cut the current body because there is a limit... That's why I set the link to stackOverFlow with the description, and the github project url is private, so you can not access to the whole code but yes to the specific issue in the needed code that I have shared in StackOverFlow.

micalevisk commented 10 months ago

Try using cURL or another http client. Could be a browser expected behavior

nikasha89 commented 10 months ago

Hi! I have tried using cURL and the behaviour is the same, I had to do another approach checking if the request and the response were logged previously, but I think the LoggingMiddleware must be triggered just one time not twice...

Thanks in advance!

Ana Rodríguez González

El jue, 4 ene 2024, 11:42, Micael Levi L. Cavalcante < @.***> escribió:

Try using cURL or another http client. Could be a browser expected behavior

— Reply to this email directly, view it on GitHub https://github.com/nestjs/nest/issues/13007#issuecomment-1876879121, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIZ2OT2QZCHSIEUFVJQ2X3YM2BQPAVCNFSM6AAAAABBMUSXZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWHA3TSMJSGE . You are receiving this because you authored the thread.Message ID: @.***>

micalevisk commented 10 months ago

so please provide a minimum reproduction repository

why reproductions are required

kamilmysliwiec commented 10 months ago

Thank you for taking the time to submit your report! From the looks of it, this could be better discussed on our Discord. If you haven't already, please join here and send a new post in the #⁠ 🐈 nestjs-help forum. Make sure to include a link to this issue, so you don't need to write it all again. We have a large community of helpful members, who will assist you in getting this to work.