Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double middleware execuation #13312

Closed
4 of 15 tasks
makbari opened this issue Mar 12, 2024 · 5 comments
Closed
4 of 15 tasks

double middleware execuation #13312

makbari opened this issue Mar 12, 2024 · 5 comments
Labels
needs triage This issue has not been looked into

Comments

@makbari
Copy link

makbari commented Mar 12, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

exclude a path in setGlobalPrefix cause middleware to trigger twice.
now, calling /api/hello will trigger the LoggerMiddleware to call twice.

without exclude: ['/'], works as expected.

Minimum reproduction code

https://codesandbox.io/p/sandbox/hopeful-pare-4wrsdk

Steps to reproduce

No response

Expected behavior

It should only call the logger middleware once

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.3

Packages versions

{
  "name": "nest-typescript-starter",
  "private": true,
  "version": "1.0.0",
  "description": "Nest TypeScript starter repository",
  "license": "MIT",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/jest/bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^10.3.2",
    "@nestjs/core": "^10.3.2",
    "@nestjs/platform-express": "^10.3.2",
    "reflect-metadata": "^0.2.1",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.3.1",
    "@nestjs/schematics": "^10.1.0",
    "@nestjs/testing": "^10.3.2",
    "@swc/cli": "^0.3.9",
    "@swc/core": "^1.4.0",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.12",
    "@types/node": "^20.11.16",
    "@types/supertest": "^6.0.2",
    "@typescript-eslint/eslint-plugin": "^6.21.0",
    "@typescript-eslint/parser": "^6.21.0",
    "eslint": "^8.56.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.1.3",
    "jest": "^29.7.0",
    "prettier": "^3.2.5",
    "source-map-support": "^0.5.21",
    "supertest": "^6.3.4",
    "ts-jest": "^29.1.2",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.3.3"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@makbari makbari added the needs triage This issue has not been looked into label Mar 12, 2024
@kamilmysliwiec
Copy link
Member

URL doesn't work (sandbox)

@makbari
Copy link
Author

makbari commented Mar 13, 2024

URL doesn't work (sandbox)

please re-open the page again and try to access the https://4wrsdk-3000.csb.app/api/hello in preview page.

@mlbonniec
Copy link

My issue is not about that (#13318), but as I'm using a middleware, I can confirm that it's executed twice in my reproduction.

@micalevisk
Copy link
Member

from what I've tested this bug exists since @nestjs/core 10.2 and probably older versions

Do you guys want to investigate it further? maybe you can start from packages/core/middleware/route-info-path-extractor.ts file

@kamilmysliwiec
Copy link
Member

Let's track this here #11832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

4 participants