No9 / harmon

middleware for node-http-proxy to modify the remote website response with trumpet
Other
424 stars 62 forks source link

Request hangs #36

Open fletchette opened 8 years ago

fletchette commented 8 years ago

Sorry that this isn't really an issue with Harmon. Its an issue with implementing it correctly. I've looked through some other issues and all the documentation but I can't figure it out -

var http = require('http'),
    connect = require('connect'),
    httpProxy = require('http-proxy');

var through = require('through');
//require("./static");

var selects = [{
    query: "head",
    func: function(elem) {
        var s = elem.createStream({outer : true });
        s.pipe(through(function(data) {
            console.log(3);
            if(data.toString().indexOf('</head>') > -1) {
                console.log(1);
                s.write('<script>alert("hello");</script>');
                console.log(2);
            }
            s.write(data);
        }));
    }
}];

var app = connect();

var proxy = httpProxy.createProxyServer({
    target: "ip_address_here"
});

proxy.on("error", function(e) {
    console.log(e);
});

app.use(require("harmon")([], selects, true));

app.use(
    function(req, res) {
        proxy.web(req, res);
    }
);

http.createServer(app).listen(80);

when I go to it in the web browser the alert pops up and then the page hangs. Thanks