const stream = require('stream');
const webpackHot = require('webpack-hot-middleware');
const PassThrough = stream.PassThrough;
module.exports = ({compiler, others}) => {
const middleware = webpackHot(compiler, others);
return async (ctx, next) => {
const res = Object.assign({}, ctx.res);
const streamInstance = new PassThrough();
streamInstance.on('data', chunk => {
if(chunk && global.cache &&global.cache.updateCache){
global.cache.updateCache();
}
});
ctx.body = streamInstance;
await middleware(
ctx.req,
Object.assign(res, {
write: streamInstance.write.bind(streamInstance),
writeHead: (
status ,
headers,
) => {
ctx.status = status;
ctx.set(headers);
},
end: (content) => {
ctx.body = content || 'devMiddleWare no body';
},
}),
next
) }
}

最新文章

  1. UGUI Text(Label)
  2. Atitit usrQBK13 html dsl 规范与解决方案
  3. MVC LINQ to SQL: Basic Concepts and Features
  4. ios学习总结(2) -- UIButton的使用
  5. jiffies和HZ
  6. SQL拆分多规则的字符串分离数字。
  7. RX学习笔记:Bootstrap
  8. 多校训练赛2 ZCC loves cards
  9. java中类的三大特征之多态
  10. 常见的UI框架
  11. POJ 1704 Georgia and Bob(阶梯Nim博弈)
  12. 头文件带和不带.h的区别
  13. Windows7下安装python3.6.3
  14. vue2.0 之事件处理器
  15. this语句的用法第一、二点
  16. Golang 反射reflection
  17. 【web技术】html特效代码(二)
  18. 【Git安装】centos安装git
  19. hdu1224 dp(dp + 栈/父亲数组记录路径)
  20. google vue开发调试插件,简便安装,亲测可用

热门文章

  1. goland 无法跳转 struct等
  2. python虚拟环境解决不能执行脚本的问题
  3. Nacos配置管理
  4. Centos 7.9 基于二进制文件部署kubernetes v1.25.5集群
  5. composer 换源
  6. Java并发编程 —— synchronized关键字
  7. 电商项目maven框架搭建引入dubbo配置文件报错
  8. Linux系统Shell脚本第四章:shell函数
  9. Linux系统Shell脚本第二章:条件测试、正整数字符串比较与if、case语句
  10. Chrome禁用开发者工具