http-proxyモジュールのインストール
npm install http-proxy
port_forwarding.js
var httpProxy = require('http-proxy');
var options = {
hostnameOnly:true,
router: {
'example.com': '127.0.0.1:8080',
'hoge.example.com': '127.0.0.1:9090'
}
}
httpProxy.createServer(options).listen(80);
80番ポートをlistenして、example.comにアクセスしてきた通信を8080ポートに、hoge.example.comでアクセスしてきた通信を9090ポートに送る。