We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
安装http-proxy-middleware模块
npm install http-proxy-middleware --save-dev
当你请求localhost:1314/api的时候,会跳转到localhost:5000/api,由于配置了pathRewrite,则会处理连接跳到localhost:5000/
localhost:1314/api
localhost:5000/api
localhost:5000/
//反向代理 var proxy = require('http-proxy-middleware'); var options = { target: 'http://localhost:5000/', // 目标主机 changeOrigin: true, // 需要虚拟主机站点 pathRewrite: { '^/api/old-path': '/api/new-path', // rewrite path '^/api': '/' // remove base path 把api的地址改为/ }, }; var exampleProxy = proxy('/api', options); //开启代理功能,并加载配置 app.use('/api', exampleProxy); //对地址为/的请求全部转发 app.listen(1314)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
安装
安装http-proxy-middleware模块
配置
当你请求
localhost:1314/api
的时候,会跳转到localhost:5000/api
,由于配置了pathRewrite,则会处理连接跳到localhost:5000/
参考文档
The text was updated successfully, but these errors were encountered: