From ca2d1ffd9b01c4325de1ba4b12f06fc16728b90a Mon Sep 17 00:00:00 2001 From: toby Date: Sun, 27 Aug 2017 21:43:08 +0800 Subject: [PATCH] only rewrite ctx.body when matched hmr request only rewrite ctx.body when matched hmr request --- middleware/hotMiddleware.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/middleware/hotMiddleware.js b/middleware/hotMiddleware.js index a5f96ba..5530fbd 100644 --- a/middleware/hotMiddleware.js +++ b/middleware/hotMiddleware.js @@ -4,10 +4,12 @@ import { PassThrough } from 'stream' export default (compiler, opts) => { const expressMiddleware = hotMiddleware(compiler, opts) return async (ctx, next) => { - let stream = new PassThrough() - ctx.body = stream + var stream = new PassThrough() await expressMiddleware(ctx.req, { - write: stream.write.bind(stream), + write: (content) => { + ctx.body = stream + stream.write(content) + }, writeHead: (status, headers) => { ctx.status = status ctx.set(headers)