1 Star 0 Fork 1

Eminoda/ssr-learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
client-hot-middleware.js 869 Bytes
一键复制 编辑 原始数据 按行查看 历史
Eminoda 提交于 6年前 . update #
const webpackHotMiddleware = require('webpack-hot-middleware');
const PassThrough = require('stream').PassThrough;
module.exports = (compiler, opts) => {
const middleware = webpackHotMiddleware(compiler, opts);
return async (ctx, next) => {
let stream = new PassThrough();
ctx.body = stream;
await middleware(
ctx.req,
{
write: stream.write.bind(stream),
// 如果以后有坑,就请注意:不建议直接使用 ctx.res 原生 response 方法,这样就跳过 koa 的处理了。https://koa.bootcss.com/#ctx-res
// write: data => {
// ctx.res.write(data);
// },
writeHead: (status, headers) => {
ctx.status = status;
ctx.set(headers);
},
end: () => {
// ctx.res.end();
ctx.body = '';
}
},
next
);
};
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/eminoda/ssr-learn.git
git@gitee.com:eminoda/ssr-learn.git
eminoda
ssr-learn
ssr-learn
webpack-server-koa

搜索帮助