Skip to content

Commit 3de1ec2

Browse files
committed
feat: remove use of pipeline
Pipeline is great for when multiple streams need to be used together but can also end up causing problems when there's a readstream of a large file being sent in chunks, because the streams get destroyed early. Technically, everything works fine, but there's warnings in the terminal that could be misleading, so calling the streams with error handlers directly is a safer way to go about it.
1 parent 3d597a4 commit 3de1ec2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

packages/platform-express/adapters/express-adapter.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type { Server } from 'http';
3030
import * as http from 'http';
3131
import * as https from 'https';
3232
import { pathToRegexp } from 'path-to-regexp';
33-
import { Duplex, pipeline } from 'stream';
33+
import { Duplex, Writable } from 'stream';
3434
import { NestExpressBodyParserOptions } from '../interfaces/nest-express-body-parser-options.interface';
3535
import { NestExpressBodyParserType } from '../interfaces/nest-express-body-parser.interface';
3636
import { ServeStaticOptions } from '../interfaces/serve-static-options.interface';
@@ -86,17 +86,13 @@ export class ExpressAdapter extends AbstractHttpAdapter<
8686
) {
8787
response.setHeader('Content-Length', streamHeaders.length);
8888
}
89-
return pipeline(
90-
body.getStream().once('error', (err: Error) => {
91-
body.errorHandler(err, response);
92-
}),
93-
response,
94-
(err: any) => {
95-
if (err) {
96-
body.errorLogger(err);
97-
}
98-
},
99-
);
89+
const stream = body.getStream();
90+
stream.once('error', err => {
91+
body.errorHandler(err, response);
92+
});
93+
return stream
94+
.pipe<Writable>(response)
95+
.on('error', (err: Error) => body.errorLogger(err));
10096
}
10197
const responseContentType = response.getHeader('Content-Type');
10298
if (

0 commit comments

Comments
 (0)