How do I proxy requests with query string parameters in nodejs, I am currently using express and http-proxy?
I have a nodejs application using express and the http-proxy module to proxy HTTP GET requests from certain paths on my end to a third party API running on the same server but a different port (and hence suffering from the same origin issue, requiring the proxy). This works fine until I want to call a REST function on the backend API with query string parameters i.e. "?name=value". I then get a 404.
var express = require('express');
var app = express();
var proxy = require('http-proxy');
var apiProxy = proxy.createProxyServer();
app.use("/backend", function(req,res){
apiProxy.web(req,res, {target: 'http://'+ myip + ':' + backendPort + '/RestApi?' + name + '=' + value});
});
Chrome's console shows:
"GET http://localhost:8080/backend 404 (Not Found)"
Notes: I use other things in express later, but not before the proxying lines and I go from more specific to more general when routing paths. The backend can be accessed directly in a browser using the same protocol://url:port/path?name=value without issue.
Use the following to append the query string parameters to the
req.url