项目 proxy.json文件里

    1. {
    2. "/heatinggo": {
    3. "target": "http://10.133.251.101:9527",
    4. "secure": false,
    5. "pathRewrite": {
    6. "^/heatinggo": ""
    7. }
    8. },
    9. "/qhj/heatinggo": {
    10. "target": "http://10.133.251.101:8080",
    11. "secure": false,
    12. "pathRewrite": {
    13. "^/qhj/heatinggo":""
    14. }
    15. }
    16. }

    我的 api=’/heatinggo’
    我的请求地址 ${api}/xxxx/xxx ,请求地址就为 ‘/heatinggo/xxxx/xxx’
    当node服务器 遇到 以 ‘/heatinggo‘ 开头的请求,就会把 target 字段加上,那么我的请求地址就为 http://10.133.251.101:9527/heatinggo/xxxx/xxx
    下面的 pathRewrite 表示的意思是 把/heatinggo 替换为 空,那么我的请求地址就为 http://10.133.251.101:9527/xxxx/xxx(用在如果你的实际请求地址没有 heatinggo 的情况)

    changeOrigin默认是false:请求头中host仍然是浏览器发送过来的host。
    如果设置成true:发送请求头中host会设置成target。