0

I am setting up a reverse proxy server with node-http-proxy and wanted to know how to pass in a variable to change the outbound request on a per-request basis. I want to make all my calls to the proxy server located at http://localhost:8000 and pass in an "extension" of sorts to the target url of the outbound requests.

For example, the target url of the real server the proxy server is calling on is at http://localhost:9999, and I want to add an extension of /config to that url. So from my front end I would fetch from http://localhost:8000 and pass in the /config extension, and the proxy server would call http://localhost:9999/config for this particular case. Does anyone know how I might go about passing in this string?

Thank you for your help.

  • Does it work if you just change the target to `http://localhost:9999/config/`? – cbr Jul 09 '21 at 16:57
  • Yes it works. But the extension is going to change depending on what I need. So it could be `/users`, `/orgs`, etc. If I change the target manually to any of them it works but I need it to change based on what the front-end needs – ElPsyCongoro Jul 09 '21 at 17:13
  • Just figured out how to change the target path URL, but still need help passing in the "extension" – ElPsyCongoro Jul 09 '21 at 17:19
  • So frontend asks for `/users` or `/orgs` and you want it to be `/config/users` and `/config/orgs`? Or do you mean that depending on which path is requested, you want to modify the path prefix ('/config') on the fly? If so, check out the documentation section on [custom logic](https://github.com/http-party/node-http-proxy#setup-a-stand-alone-proxy-server-with-custom-server-logic) – cbr Jul 09 '21 at 17:22

0 Answers0