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

fix(core): let the middleware can get the params in the global prefix #10390

Merged
merged 21 commits into from Feb 3, 2023

Conversation

CodyTseng
Copy link
Contributor

@CodyTseng CodyTseng commented Oct 10, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #9776, #10566

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

coveralls commented Oct 10, 2022

Pull Request Test Coverage Report for Build 88e8b676-a087-4894-ad55-c3b4e77ab62f

  • 29 of 30 (96.67%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 92.997%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/microservices/server/server-kafka.ts 0 1 0.0%
Totals Coverage Status
Change from base Build 2f44b0f1-4e06-49ac-b845-35bef850e129: 0.03%
Covered Lines: 6401
Relevant Lines: 6883

💛 - Coveralls

@CodyTseng CodyTseng marked this pull request as ready for review October 11, 2022 07:49
@mareksuscak
Copy link

mareksuscak commented Nov 15, 2022

Does this pull request fix the issue described in #8844 (comment) by any chance? If not, can we please fix that bug in this PR please and add some tests? Please let me know if that's not possible and I'll create a separate issue and open a PR.

EDIT: here's the ticket in case you decide to fix the bug #10566

@CodyTseng
Copy link
Contributor Author

@mareksuscak I think I can get this PR to fix #10566 with a few small tweaks. But I think this should be two different questions. I'm not sure if we need to open another PR.

@kenji57775
Copy link

kenji57775 commented Nov 18, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #9776

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@CodyTseng
Copy link
Contributor Author

@mareksuscak Hi, I tried to fix the issue described in #8844 (comment) and added some tests in this PR. I’d appreciate it if you have time to review the commit and give me some advice.

Copy link
Contributor

@thiagomini thiagomini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @CodyTseng, I haven't had time to look into this issue since last week. I left a few suggestions for you, and I hope you find them useful 😄

packages/core/middleware/middleware-module.ts Outdated Show resolved Hide resolved
packages/core/middleware/utils.ts Outdated Show resolved Hide resolved
@CodyTseng
Copy link
Contributor Author

Thanks for your useful suggestions, @thiagomini ! I will look carefully at your suggestions and optimize the code later.

@CodyTseng CodyTseng requested review from thiagomini and removed request for zanminkian November 23, 2022 14:58
Copy link
Contributor

@thiagomini thiagomini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Cody, first, I would like to thank you again for your efforts to contribute to NestJS. Nonetheless, I ask you to review the tests you've created here. I hope my explanation clarified why we should avoid testing private methods, but let me know if you are not sure yet.

packages/core/test/middleware/middleware-module.spec.ts Outdated Show resolved Hide resolved
packages/core/test/middleware/middleware-module.spec.ts Outdated Show resolved Hide resolved
packages/core/test/nest-application.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@thiagomini thiagomini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM (Looks good to me) now, Cody. Thanks for considering my reviews 😃

packages/core/middleware/route-info-path-extractor.ts Outdated Show resolved Hide resolved
@thiagomini
Copy link
Contributor

thiagomini commented Nov 25, 2022

Hey @kamilmysliwiec , could you review this too?

@kamilmysliwiec
Copy link
Member

Apologies for not reviewing this PR sooner.. There's a few conflicts that occurred after we introduced a new PathsExplorer class https://github.com/nestjs/nest/blob/master/packages/core/router/paths-explorer.ts. Would you be able to resolve them @CodyTseng?

@CodyTseng
Copy link
Contributor Author

Of course! I will resolve the conflict later.

@CodyTseng
Copy link
Contributor Author

Hey @kamilmysliwiec, I've resolved conflicts. You can review it when you have time 😊

@kamilmysliwiec
Copy link
Member

I'm wondering if this PR solves this issue #9990 as well 🤔

@CodyTseng
Copy link
Contributor Author

Unfortunately, this issue #9990 has not been solved in this PR.

I'm also following this issue, if I think of a suitable solution, I'd be happy to create a PR for it. I think the following method needs to be modified.

export function isMiddlewareRouteExcluded(
req: Record<string, any>,
excludedRoutes: ExcludeRouteMetadata[],
httpAdapter: HttpServer,
): boolean {
if (excludedRoutes.length <= 0) {
return false;
}
const reqMethod = httpAdapter.getRequestMethod(req);
const originalUrl = httpAdapter.getRequestUrl(req);
const queryParamsIndex = originalUrl && originalUrl.indexOf('?');
const pathname =
queryParamsIndex >= 0
? originalUrl.slice(0, queryParamsIndex)
: originalUrl;
return isRouteExcluded(excludedRoutes, pathname, RequestMethod[reqMethod]);
}

Co-authored-by: Kamil Mysliwiec <mail@kamilmysliwiec.com>
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants