Skip to content

Commit

Permalink
docs(faq): add docs for force close connections option
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgap committed Oct 1, 2023
1 parent a53ab1e commit 1de38b3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions content/faq/keep-alive-connections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Keep alive connections

By default, the HTTP adapters of NestJS will wait until the response is finished before closing the application. But sometimes, this behavior is not desired, or unexpected. There might be some requests that use `Connection: Keep-Alive` headers that live for a long time.

For these scenarios where you always want your application to exit without waiting for requests to end, you can enable the `forceCloseConnections` option when creating your NestJS application.

> warning **Tip** Most users will not need to enable this option. But the symptom of needing this option is that your application will not exit when you expect it to. Usually when `app.enableShutdownHooks()` is enabled and you notice that the application is not restarting/exiting. Most likely while running the NestJS application during development with `--watch`.
#### Usage

In your `main.ts` file, enable the option when creating your NestJS application:

```typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule, {
forceCloseConnections: true,
});
await app.listen(3000);
}

bootstrap();
```
4 changes: 4 additions & 0 deletions src/app/homepage/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export class MenuComponent implements OnInit {
children: [
{ title: 'Serverless', path: '/faq/serverless' },
{ title: 'HTTP adapter', path: '/faq/http-adapter' },
{
title: 'Keep-Alive connections',
path: '/faq/keep-alive-connections',
},
{ title: 'Global path prefix', path: '/faq/global-prefix' },
{ title: 'Raw body', path: '/faq/raw-body' },
{ title: 'Hybrid application', path: '/faq/hybrid-application' },
Expand Down
7 changes: 7 additions & 0 deletions src/app/homepage/pages/faq/faq.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ErrorsComponent } from './errors/errors.component';
import { GlobalPrefixComponent } from './global-prefix/global-prefix.component';
import { HttpAdapterComponent } from './http-adapter/http-adapter.component';
import { HybridApplicationComponent } from './hybrid-application/hybrid-application.component';
import { KeepAliveConnectionsComponent } from './keep-alive-connections/keep-alive-connections.component';
import { MultipleServersComponent } from './multiple-servers/multiple-servers.component';
import { RawBodyComponent } from './raw-body/raw-body.component';
import { RequestLifecycleComponent } from './request-lifecycle/request-lifecycle.component';
Expand All @@ -32,6 +33,11 @@ const routes: Routes = [
component: HttpAdapterComponent,
data: { title: 'HTTP adapter - FAQ' },
},
{
path: 'keep-alive-connections',
component: KeepAliveConnectionsComponent,
data: { title: 'Keep-Alive connections - FAQ' },
},
{
path: 'raw-body',
component: RawBodyComponent,
Expand Down Expand Up @@ -61,6 +67,7 @@ const routes: Routes = [
HybridApplicationComponent,
MultipleServersComponent,
HttpAdapterComponent,
KeepAliveConnectionsComponent,
RequestLifecycleComponent,
ErrorsComponent,
ServerlessComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { BasePageComponent } from '../../page/page.component';

@Component({
selector: 'keep-alive-connections',
templateUrl: './keep-alive-connections.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class KeepAliveConnectionsComponent extends BasePageComponent {}

0 comments on commit 1de38b3

Please sign in to comment.