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

ApplicationReferenceHost.applicationRef.httpServer is undefined when using the FastifyAdapter #1391

Closed
BrunnerLivio opened this issue Dec 20, 2018 · 4 comments

Comments

@BrunnerLivio
Copy link
Member

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When using the FastifyAdapter will make ApplicationReferenceHost.applicationRef.httpServer undefined.
In case you do not use FastifyAdapter, it will work as expected.

main.ts

NestFactory.create(
      ApplicationModule.forRoot(options),
      new FastifyAdapter(),
    );

terminus-bootstrap.service.ts

@Injectable()
export class TerminusBootstrapService implements OnApplicationBootstrap {
  constructor(
    private readonly refHost: ApplicationReferenceHost,
  ) {}

  public onApplicationBootstrap() {
    this.refHost.applicationRef.httpServer; // Returns null

  }
}

Expected behavior

It should return the underlying HttpServer

What is the motivation / use case for changing the behavior?

@nestjs/terminus does not work with FastifyAdapter because of this.

Environment


Nest version: 5.5.0

For Tooling issues:
- Node version: 10
- Platform:  Linux

Others:
https://github.com/nestjs/terminus/issues/24
@BrunnerLivio
Copy link
Member Author

Fixed this issue with:

// httpServer for express, instance.server for fastify
const httpServer =
      this.refHost.applicationRef.httpServer ||
      this.refHost.applicationRef.instance.server;

Seems like instance.server returns the httpServer of fastify. I think this is a workaround, so I guess I leave this issue open for now?

@marcus-sa
Copy link

marcus-sa commented Dec 28, 2018

Now I can't remember exactly what interface applicationRef returns, but from looking at the adapters, calling getHttpServer() returns the correct server instance for both.

getHttpServer<T = any>(): T {
return this.httpServer as T;
}

getHttpServer<T = any>(): T {
return this.instance.server as T;
}

@BrunnerLivio
Copy link
Member Author

@marcus-sa Perfect, works! This seems like a nice solution, closing :)

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants