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

Middleware fails on path excluded from the global prefix #93

Closed
murbanowicz opened this issue Dec 13, 2023 · 3 comments
Closed

Middleware fails on path excluded from the global prefix #93

murbanowicz opened this issue Dec 13, 2023 · 3 comments
Labels
investigation Why is this happening?

Comments

@murbanowicz
Copy link

Hi,
I hit weird issue with this great library.
I have a global prefix on my service declared like this:

  app.setGlobalPrefix('orders', {
    exclude: [
      'readiness',
      'liveness',
      'dapr/subscribe',
      '(.*)subscription(.*)',
    ],
  });

The issue is about the middleware not working for paths excluded from global prefix.

No idea why to be honest.

@Papooch
Copy link
Owner

Papooch commented Dec 13, 2023

This is most likely an issue with Nest itself than with this library. Maybe also related to this: #92 ?

The library is only mounting the middleware to * by default and then Nest does with it what it wants.
What you can do to try and fix it on your end is mount the middleware manually for specific routes.


However, I'd like to speak from experiance and say that I never had a good time with setting things globally and then excluding some of the things. It makes for less readable code, because you have to always check if that particular thing is excluded or not and you're not always sure where to look for this information.

So I now never use global prefix (unless it is api and there are no exceptions) and instead just either repeat it in on the top of each controller (while re-using a constant, of course - e.g. Controller(`${GLOBAL_PATH}`/users). This gives you the possibility to explicitly opt-out of the global prefix while keeping the information localized where it is used, instead of hiding it in some configuration file somewhere else. Another alternative is using the RouterModule to create a hieararchy of controllers - which is what I would probably advise in your situation so you don't have to change your controllers.

@Papooch Papooch added the investigation Why is this happening? label Dec 13, 2023
@Papooch
Copy link
Owner

Papooch commented Dec 19, 2023

@murbanowicz Hi, have you investigated this further or did my response help you move forward?

@Papooch
Copy link
Owner

Papooch commented Jan 17, 2024

I am assuming the issue is either solved or not relevant. Closing.

@Papooch Papooch closed this as completed Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigation Why is this happening?
Projects
None yet
Development

No branches or pull requests

2 participants