Skip to content

Commit

Permalink
docs: add http adapter listen stream docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 15, 2024
1 parent 27d1890 commit b1a9402
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion content/faq/http-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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');
}
```

0 comments on commit b1a9402

Please sign in to comment.