2015-03-30 27 views
1

我使用nodejs和node-http-proxy以及harmon。我正在使用harmon來重寫代理響應,以包含一個JavaScript文件和一個css文件。當我將代理的目標設置爲http://nodejs.org或localhost以外的任何其他目標時,我會收到301或302重定向。該腳本正在重寫301響應,而不是完全代理的響應。我如何使用harmon來重寫最終響應而不是302響應?nodejs:node-http-proxy和harmon:從終點重寫html響應,而不是302重定向響應。

這裏是我從哈蒙例如文件夾運行腳本的例子:

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

var selects = []; 
var simpleselect = {}; 

//<img id="logo" src="/images/logo.svg" alt="node.js"> 
simpleselect.query = 'img'; 
simpleselect.func = function (node) { 

//Create a read/write stream wit the outer option 
//so we get the full tag and we can replace it 
var stm = node.createStream({ "outer" : true }); 

//variable to hold all the info from the data events 
var tag = ''; 

//collect all the data in the stream 
stm.on('data', function(data) { 
    tag += data; 
}); 

//When the read side of the stream has ended.. 
stm.on('end', function() { 

    //Print out the tag you can also parse it or regex if you want 
    process.stdout.write('tag: ' + tag + '\n'); 
    process.stdout.write('end: ' + node.name + '\n'); 

    //Now on the write side of the stream write some data using .end() 
    //N.B. if end isn't called it will just hang. 
    stm.end('<img id="logo" src="http://i.imgur.com/LKShxfc.gif"   alt="node.js">');  

    });  
} 

    selects.push(simpleselect); 

// 
// Basic Connect App 
// 
var app = connect(); 

var proxy = httpProxy.createProxyServer({ 
    target: 'http://nodejs.org' 
}) 


app.use(require('../')([], selects, true)); 

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

回答

0

的問題是,很多網站現在都重定向HTTP到HTTPS。 nodejs.org就是其中之一。

我已更新示例https://github.com/No9/harmon/blob/master/examples/doge.js以顯示如何配置http代理以處理HTTPS。

如果您仍然有其他任意重定向的問題,請登錄關於和諧的問題。

謝謝