方法1:http-server -p 3000 -P http://地址
eg:http-server -p 3000 -P http://123.com
方法2:
1.首先安裝 express http-proxy-middleware
2.加入如下代碼
var express = require('express');
var proxy = require('http-proxy-middleware');
var app = express();
app.use('/api', proxy({target: 'http://地址', changeOrigin: true})); //全部api的請求地址都會使用代理
app.get('/', function (req, res) {
res.sendFile( __dirname + "/" + "index.html" );
})
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
3.node app.js
除外http-server改變端口方法
http-server -p 8000