fix(core): proper way for detecting Node.js streams
MODIFY
packages/core/src/+internal/utils/stream.util.ts
packages/core/src/+internal/utils/stream.util.ts
import * as stream from 'stream';
-export const isReadableStream = (data: any): data is stream.Readable =>
- data instanceof stream.Readable;
+export const isStream = (stream: any): stream is stream.Stream =>
+ stream !== null &&
+ typeof stream === 'object' &&
+ typeof stream.pipe === 'function';

MODIFY
packages/core/src/response/response.handler.ts
packages/core/src/response/response.handler.ts
@@ -3,7 +3,7 @@ import { HttpEffectResponse } from '../effects/http-effects.interface';
import { HttpRequest, HttpResponse, HttpStatus } from '../http.interface';
import { bodyFactory } from './responseBody.factory';
import { headersFactory } from './responseHeaders.factory';
-import { isReadableStream } from '../+internal/utils';
+import { isStream } from '../+internal/utils';
export const handleResponse = (res: HttpResponse) => (req: HttpRequest) => (effect: HttpEffectResponse) => {
if (res.finished) { return EMPTY; }
@@ -16,7 +16,7 @@ export const handleResponse = (res: HttpResponse) => (req: HttpRequest) => (effe
const bodyFactoryWithHeaders = bodyFactory(headers);
const body = bodyFactoryWithHeaders(effect.body);
- if (isReadableStream(body)) {
+ if (isStream(body)) {
res.writeHead(status, headers);
body.pipe(res);
} else {

fix(core): proper way for detecting Node.js streams