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

HttpHealthIndicator is marked as a scoped provider, causing the server to not start up with the usage of the HttpHealthCheckStrategy #2617

Closed
sidings opened this issue Jan 9, 2024 · 1 comment
Assignees
Labels
type: bug 🐛 Something isn't working

Comments

@sidings
Copy link

sidings commented Jan 9, 2024

Describe the bug
The HttpHealthCheckStrategy uses the HttpHealthIndicator provided by the @nestjs/terminus package. When using the HttpHealthCheckStrategy as one of the application health checks, the server fails to start up and throws an error:

InvalidClassScopeException [Error]: HttpHealthIndicator is marked as a scoped provider. Request and transient-scoped providers can't be used in combination with "get()" method. Please, use "resolve()" instead.

This wasn't happening when I was using Vendure version 1.9.5, but is now happening when I'm on version 2.0.4.

To Reproduce
Steps to reproduce the behavior:

  1. Add the following to the vendure-config.ts file.
    systemOptions: {
    healthChecks: [
     new HttpHealthCheckStrategy({
       key: 'admin-ui-probe',
       url: <URL>,
     }),
    ],
    
  2. Start the server.
  3. See error in the logs.

Expected behavior
I expect the server to start up properly and the health check to be initialized.

Environment (please complete the following information):

  • @vendure/core version: 2.0.4
  • Nodejs version: 18
  • Database (mysql/postgres etc): Postgres

Additional context
Add any other context about the problem here.

@sidings sidings added the type: bug 🐛 Something isn't working label Jan 9, 2024
@michaelbromley michaelbromley moved this to 📋 Backlog in Vendure OS Roadmap Jan 9, 2024
@michaelbromley
Copy link
Member

OK I found a couple of issues going on here:

  1. First of all, we were using the injector.get(HttpHealthIndicator) method but NestJS requires the use of injector.resolve(HttpHealthIndicator) in this case. That was probably an API change that I didn't notice in one of the updates.
  2. But resolving that issue exposed a deeper issue: due to internal changes in some earlier NestJS versions, the HttpHealthIndicator depends on the @nestjs/axios and axios packages being installed, and the HttpModule being imported into the core.

Since I don't really want to add 2 new dependencies for this single case (which is probably quite rarely used), I will create a custom health indicator which has no new dependencies for the next patch version.

@michaelbromley michaelbromley moved this from 📋 Backlog to 🔖 Ready in Vendure OS Roadmap Jan 12, 2024
@michaelbromley michaelbromley moved this from 🔖 Ready to ✅ Done in Vendure OS Roadmap Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working
Projects
Status: 🚀 Shipped
Development

No branches or pull requests

2 participants