Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Commit 14c78d2

Browse files
committed
fix: remove unecessary mem leak causing cleanup
1 parent 826321b commit 14c78d2

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

lib/middleware.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,20 @@ module.exports = class Middleware extends EventEmitter {
8383
js() {
8484
return (req, res, next) => {
8585
res.type('javascript');
86-
const bundler = this.writers.js.bundle();
87-
88-
bundler.on('error', cleanup);
89-
90-
const writeStream = bundler.pipe(res).on('error', cleanup);
91-
92-
function cleanup(e) {
93-
res.write(`console.error(${JSON.stringify(e.stack)})`);
94-
bundler.pause();
95-
bundler.unpipe(writeStream);
96-
writeStream.end();
97-
next(e);
98-
}
86+
this.writers.js
87+
.bundle()
88+
.on('error', next)
89+
.pipe(res);
9990
};
10091
}
10192

10293
css() {
10394
return (req, res, next) => {
10495
res.type('css');
105-
const bundler = this.writers.css.bundle();
106-
107-
bundler.on('error', cleanup);
108-
109-
const writeStream = bundler.pipe(res).on('error', cleanup);
110-
111-
function cleanup(e) {
112-
res.write(`console.error(${JSON.stringify(e.stack)})`);
113-
bundler.pause();
114-
bundler.unpipe(writeStream);
115-
writeStream.end();
116-
next(e);
117-
}
96+
this.writers.css
97+
.bundle()
98+
.on('error', next)
99+
.pipe(res);
118100
};
119101
}
120102
};

0 commit comments

Comments
 (0)