鍍金池/ 問答/Linux  HTML/ http-proxy-middle代碼URL的問題

http-proxy-middle代碼URL的問題

app.use(`/apiProxy`, proxy({
  target: 'http://172.17.123.131:10241',
  // target: 'http://172.17.123.216:4000',
  changeOrigin: true,
  logLevel: 'debug',
  proxyReq: function (req) {
    console.log(req)
  }
}));

when i ajax get('/apiProxy/TaxRate/GetTaxRates') i want to refer to http://172.17.123.131:10241/TaxRate/GetTaxRates

not http://172.17.123.131:10241/apiProxy/TaxRate/GetTaxRates

How did i do this?

回答
編輯回答
初念

add pathRewrite like:

proxy({
    ...
    pathRewrite: {
          '^/apiProxy' : '/'           
    },
})
2018年5月30日 19:17
編輯回答
青瓷

這個中間件有一個pathRewrite屬性,你對著文檔設置一下就行了。

2017年4月28日 08:36