下面是我使用的模塊版本:如何使用node-http-proxy進行HTTP到HTTPS路由?
$ npm list -g | grep proxy
├─┬ [email protected]
一個Web服務調用到我的機器,我的任務是代理請求基於的內容不同的URL和主機有一個額外的查詢參數請求體:
var http = require('http'),
httpProxy = require('http-proxy')
form2json = require('form2json');
httpProxy.createServer(function (req, res, proxy) {
// my custom logic
var fullBody = '';
req.on('data', function(chunk) {
// append the current chunk of data to the fullBody variable
fullBody += chunk.toString();
});
req.on('end', function() {
var jsonBody = form2json.decode(fullBody);
var payload = JSON.parse(jsonBody.payload);
req.url = '/my_couch_db/_design/ddoc_name/_update/my_handler?id="' + payload.id + '"';
// standard proxy stuff
proxy.proxyRequest(req, res, {
changeOrigin: true,
host: 'my.cloudant.com',
port: 443,
https: true
});
});
}).listen(8080);
,但我一直運行到類似的錯誤:An error has occurred: {"code":"ECONNRESET"}
任何人有需要被固定在這裏有什麼想法?
謝謝阿龍,這是我在很長一段時間和一個實際工作收到關於這一主題的第一個有用的答案! – pulkitsinghal 2013-09-09 20:31:24