Is there any way to dynamically change target depending on request headers?
PS. I tried your router thing, but for it, I still need to predefine urls, however I need them to be fully dynamic.
You should still be able to define fully dynamic targets with the router, as it accepts the request, from which you can grab the headers. So, something like this:
app.use(proxy({
target: 'http://example.com',
router (req) => {
let newTarget = req.headers['my-header-containing-the-url-or-flag']
// ... transformation logic ... //
return newTarget
}
})
@UseHandsfree Thanks for contribution, that works well!
Most helpful comment
You should still be able to define fully dynamic targets with the router, as it accepts the request, from which you can grab the headers. So, something like this: