From b1a940297b3874002729ef0a0d62a7334ba77784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Fri, 15 Nov 2024 14:54:44 +0100 Subject: [PATCH] docs: add http adapter listen stream docs --- content/faq/http-adapter.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/content/faq/http-adapter.md b/content/faq/http-adapter.md index 03cd02317f..58f849db1c 100644 --- a/content/faq/http-adapter.md +++ b/content/faq/http-adapter.md @@ -14,7 +14,7 @@ const app = await NestFactory.create(AppModule); const httpAdapter = app.getHttpAdapter(); ``` -#### In-context strategy +#### As injectable To get a reference to the `HttpAdapterHost` from within the application context, inject it using the same technique as any other existing provider (e.g., using constructor injection). @@ -48,3 +48,21 @@ The adapter object exposes several useful methods to interact with the HTTP serv ```typescript const instance = httpAdapter.getInstance(); ``` + +#### Listening event + +To execute an action when the server begins listening for incoming requests, you can subscribe to the `listen$` stream, as demonstrated below: + +```typescript +this.httpAdapterHost.listen$.subscribe(() => + console.log('HTTP server is listening'), +); +``` + +Additionally, the `HttpAdapterHost` provides a `listening` boolean property that indicates whether the server is currently active and listening: + +```typescript +if (this.httpAdapterHost.listening) { + console.log('HTTP server is listening'); +} +```