express-request-proxy
express-request-proxy copied to clipboard
Replacements not allowed outside parameters
Got a destination URL (which I don't control) as something.com/api?client_id=:id (rather than the more elegant /api/client/:id). When running requestProxy({url: "something.com/api?client_id=:id" }), that actual requested URL ends up being ...?client_id=%3Aid (no interpolation). Tried a quick /api/client/:id sanity-check and that interpolates fine.
I see query support, but not for tokens passed into the URL. Seems tokens only support params. Any thoughts?
One thought that comes to mind is to have a special colon prefixed value in the query object that would pull from params. For example if you were wanting to hit a remote api with the url https://api.something.com/client?client_id=1234 but you want your client code to use the more RESTful /api/client/1234, you might configure it like so:
app.get('/api/client/:clientId', requestProxy({
url: 'https://api.something.com/client',
query: {
client_id: ':clientId' // note the colon prefix
}
}));
The proxy code would need to change to detect the leading ":" on the query value and interpret that as an instruction to substitute the param with that name.
Does that sound like it would address your use case? PRs always welcome ;)
That would be the perfect solution! Alas, I moved to https://github.com/villadora/express-http-proxy (manual URL construction allowed me to get my thing done), so won't be PR-ing unless I hop back. I might, given how the proxying details pan out, but if not thanks for the consideration!