我正在使用http-proxy-middleware
如何转发这样在管道中计算出的参数?
以下示例未将参数转发到后端
const proxy = require('http-proxy-middleware')
// here I add user Id as a parameter
const forwardId = (req, res, next) => {
req.params.userId = req.user.userId
next()
}
const options = {
target: `http://backend-server`, // target host
pathRewrite: {
'^/user': '/'
}
}
// I want to interogate backend-server with as parameter, the userId that I extracted in forwardId function
router.get('/user', forwardId, proxy(options))