在我的请求中添加参数并将其代理

时间:2018-08-07 09:32:48

标签: javascript express http-proxy-middleware

我正在使用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))

0 个答案:

没有答案