const http = require('http'); const httpProxy = require('http-proxy'); //創建一個代理服務 const proxy = httpProxy.createProxyServer(); //創建http服務器並監聽8888端口 let server = http.createServer(function (req, res) { //將用戶的請求轉發到本地9999端口上 proxy.web(req, res, { target: 'http://localhost:9999' }); //監聽代理服務錯誤 proxy.on('error', function (err) { console.log(err); }); }); server.listen(8888, '0.0.0.0');