feat(common): add option to enable force closing http connections

This commit is contained in:
Tolga Paksoy
2022-10-20 16:49:23 +02:00
parent 5d1ac89637
commit dd3a773985
2 changed files with 11 additions and 4 deletions

View File

@@ -25,4 +25,9 @@ export interface NestApplicationOptions extends NestApplicationContextOptions {
* Whether to register the raw request body on the request. Use `req.rawBody`.
*/
rawBody?: boolean;
/**
* Force close open HTTP connections. Useful if restarting your application hangs due to
* keep-alive connections in the HTTP adapter.
*/
forceCloseConnections?: boolean;
}

View File

@@ -205,11 +205,13 @@ export class ExpressAdapter extends AbstractHttpAdapter {
options.httpsOptions,
this.getInstance(),
);
this.trackOpenConnections();
return;
} else {
this.httpServer = http.createServer(this.getInstance());
}
if (options?.forceCloseConnections === true) {
this.trackOpenConnections();
}
this.httpServer = http.createServer(this.getInstance());
this.trackOpenConnections();
}
public registerParserMiddleware(prefix?: string, rawBody?: boolean) {