0
我的代碼:如何使用node-http-proxy進行302重定向?
var path = require('path');
var util = require('util');
var http = require('http');
var fs = require('fs');
var httpProxy = require('http-proxy');
httpProxy.createProxyServer({
target: 'http://localhost:9000',
agent: https.globalAgent,
headers: {
host: 'localhost'
}
})
.listen(8000);
util.puts('proxy server listening on port 8000');
http.createServer(function targetServer(req, res) {
res.writeHead(302, { 'Location': '/' }); //Here is the 302
util.puts('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
})
.listen(9000);
util.puts('target server listening on port 9000');
當我提出從我的瀏覽器我得到以下錯誤請求:
Error: socket hang up
我不知道這是什麼錯誤表示。任何人都可以幫我解決這個問題嗎?