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

While using .registerAsync with custom controller, custom controller not working and path is ignored #2279

Closed
murbanowicz opened this issue May 23, 2024 · 9 comments
Labels
question Further information is requested released

Comments

@murbanowicz
Copy link

I found this really weird issue.
When using useFactory / registerAsync, the custom controller does not work properly.

I have to use configuration, so I moved to async creation and I hit this issue which I cannot even workaround :/

If custom controller is passed to the options while using registerAsync, the controller is not used, but the base prom controller is being used and on top of that the path is being ignored completely.

@willsoto
Copy link
Owner

Can you provide a minimal reproduction please?

@willsoto willsoto added the question Further information is requested label May 23, 2024
@murbanowicz
Copy link
Author

murbanowicz commented May 23, 2024

Yes please. Simple test showcasing the issue.
https://github.com/murbanowicz/nestjs-prometheus/blob/register-async-controller-issue/test/custom-controller.spec.ts

I went through the code but did not find anything obvious :/

@willsoto
Copy link
Owner

Thanks. I will take a look hopefully later today or tomorrow

@murbanowicz
Copy link
Author

Thanks! That you for such a quick reaction.

@willsoto
Copy link
Owner

Out of curiosity, do you need to actually inject anything into the controller via the useFactory?

@murbanowicz
Copy link
Author

I need to inject config to set custom labels.
I could workaround it but it is still a bug (which I can't figure out so far while looking through the code :/

@willsoto
Copy link
Owner

willsoto commented May 24, 2024

Just to be clear, you are trying to inject something into the controller itself?

The whole reason the "custom controller" feature was added was to support Fastify. There really isn't any logic in that controller. Setting custom labels you can do via configuration only.

It's a mistake that I allow it to go in the main options, it should only exist outside the useFactory, etc. Like so:

PrometheusModule.registerAsync({
  controller: CustomController,
  useFactory() {
    // whatever goes here
    return {};
  },
});

@willsoto
Copy link
Owner

willsoto commented Jun 5, 2024

@murbanowicz Is this issue resolved for you?

willsoto pushed a commit that referenced this issue Jun 6, 2024
## [6.0.1](v6.0.0...v6.0.1) (2024-06-06)

### Bug Fixes

* don't allow controller to be declared on options ([6924ffa](6924ffa)), closes [#2279](#2279)
@willsoto
Copy link
Owner

willsoto commented Jun 6, 2024

🎉 This issue has been resolved in version 6.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested released
Projects
None yet
Development

No branches or pull requests

2 participants