const express = require(‘express‘); const path = require(‘path‘); const request = require(‘request‘); // 配置静态文件服务中间件 // server地址 const app = express(); // 设置访问地址 let serverUrl = ‘http://www.baidu.com‘; app.use(express.static(path.join(__dirname, ‘./‘))); //静态资源index.html和node代码在一个目录下 app.use(‘/‘, function(req, res) { let url = serverUrl + req.url; req.pipe(request(url)).pipe(res); }); // 指定本地服务ip地址,开启本地服务端口 app.listen(8088, ‘192.168.1.18‘, function() { console.log(‘server is running at port 8088‘); });