var http = require('http');
var httpProxy = require('http-proxy');
var PORT = 1234;
//创建代理服务器监听捕获异常事件
var proxy = httpProxy.createProxyServer();
proxy.on('error',function(err,req,res){
res.end();//异常事件不处理
});
var app = http.createServer(function(req,res){
//执行反向代理
proxy.web(req,res,{
//目标地址
target:'https://www.baidu.com',
changeOrigin: true,
});
});
app.listen(PORT ,'192.168.200.84',function(){
console.log('server is runing at %d',PORT);
});