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

add optional controller support #31

Closed
wants to merge 2 commits into from

Conversation

marsprince
Copy link

@marsprince marsprince commented Oct 10, 2018

Sometime we need directly define controller's path because not all path finder in nestjs equal
to module path + controller path.

For example, in Middleware
consumer.apply(someMiddleware).forRoutes(SomeController);
it only find PATH_METADATA, not MODULE_PATH.

The change in PR also make us lose ability to define own route in Decorator @controller,but I think it is not important. Decorator route in controller class is not necessary with nested routes.

@coveralls
Copy link

coveralls commented Oct 10, 2018

Pull Request Test Coverage Report for Build 95

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 82: 0.0%
Covered Lines: 22
Relevant Lines: 22

💛 - Coveralls

@shekohex
Copy link
Member

Hi @marsprince , thank you for your contribution 😃.

But i didn't get your idea of adding controller property to the options.

Can you clarify or maybe what is the main use cases here for that? 😃

@marsprince
Copy link
Author

marsprince commented Oct 12, 2018

Hi @marsprince , thank you for your contribution 😃.

But i didn't get your idea of adding controller property to the options.

Can you clarify or maybe what is the main use cases here for that? 😃

Sorry, my English is poor.

As I know, MODULE_PATH is only used by routes-resolver.
https://github.com/nestjs/nest/blob/85d7384b5e2b486af42d13c7940ee2e3fa63256d/packages/core/router/routes-resolver.ts#L43

Then nestjs will register router by modulePath + basePath.

But in other places such as middleware, It find path by PATH_METADATA
https://github.com/nestjs/nest/blob/85d7384b5e2b486af42d13c7940ee2e3fa63256d/packages/core/middleware/routes-mapper.ts#L28

So if I use module path , It can't not find whole path(module path+method path), the path defined in MODULE_PATH can't be found. So the middleware's applied router is wrong.

I'm a newer in nestjs and I don't know how to solve it , so I use an option to directly define controller. Thank you!

@marsprince
Copy link
Author

marsprince commented Oct 12, 2018

Example
const routes: Routes = [ { path: '/a', module: ModuleA, }, ]; @Controller('c') ControllerA

In moduleA,I use
consumer.apply(middleware).forRoutes(ControllerA);

It applied in router /c not /a/c

@shekohex
Copy link
Member

Thank you @marsprince 🙂 , I will review that PR and will inform you what i think.

@shekohex
Copy link
Member

Hi @marsprince , I really appreciate your hard work.
after thinking about that for some time, i just made a new PR #32 that will solve this issue in better way.

Thank you again for that 👍
btw, can you help in making a usage of that in examples ?

@shekohex shekohex closed this Oct 14, 2018
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.

3 participants