问题描述
我正在使用 http-proxy 和 harmon 构建网络代理,并尝试将脚本标记注入 HTML 正文,但问题是它始终无法正常工作。我猜它是为较小的站点注入脚本,而不是为大型站点注入脚本,我不知道为什么会发生这种情况
const httpProxy = require("http-proxy");
const express = require('express');
const app = express();
const proxy = httpProxy.createProxyServer({
secure: false,changeOrigin: true,});
proxy.on('proxyRes',function(proxyRes,req,res) {
proxyRes.headers['content-security-policy'] = undefined;
proxyRes.headers['x-frame-options'] = undefined;
});
app.use(require('harmon')([],[{
query: 'body',func: function(node) {
// Soomething happening here...
const out = `<script src="http://localhost:5000/sample.js"></script>`;
const rs = node.createReadStream();
const ws = node.createWriteStream({
outer: false
});
// Read the node and put it back into our write stream,// but don't end the write stream when the readStream is closed.
rs.pipe(ws,{
end: false
});
// When the read stream has ended,attach our style to the end
rs.on('end',function(data) {
ws.end(out);
});
}
}]));
app.use((req,res) => {
proxy.web(req,res,{ target: 'http://example.com' });
});
app.listen(3000,() => {
console.log('Listening....')
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)