Skip to content

Commit b1a9402

Browse files
docs: add http adapter listen stream docs
1 parent 27d1890 commit b1a9402

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

content/faq/http-adapter.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const app = await NestFactory.create(AppModule);
1414
const httpAdapter = app.getHttpAdapter();
1515
```
1616

17-
#### In-context strategy
17+
#### As injectable
1818

1919
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).
2020

@@ -48,3 +48,21 @@ The adapter object exposes several useful methods to interact with the HTTP serv
4848
```typescript
4949
const instance = httpAdapter.getInstance();
5050
```
51+
52+
#### Listening event
53+
54+
To execute an action when the server begins listening for incoming requests, you can subscribe to the `listen$` stream, as demonstrated below:
55+
56+
```typescript
57+
this.httpAdapterHost.listen$.subscribe(() =>
58+
console.log('HTTP server is listening'),
59+
);
60+
```
61+
62+
Additionally, the `HttpAdapterHost` provides a `listening` boolean property that indicates whether the server is currently active and listening:
63+
64+
```typescript
65+
if (this.httpAdapterHost.listening) {
66+
console.log('HTTP server is listening');
67+
}
68+
```

0 commit comments

Comments
 (0)