I\'ve written a small proxy with nodejs, express and htt-proxy. It works well for serving local files but fails when it comes to proxy to external api:
var e
That's what I've been using for a while. Can handle both JSON and binary requests.
app.use('/api', (req, res, next) => {
const redirectUrl = config.api_server + req.url.slice(1);
const redirectedRequest = request({
url: redirectUrl,
method: req.method,
body: req.readable ? undefined : req.body,
json: req.readable ? false : true,
qs: req.query,
// Pass redirect back to the browser
followRedirect: false
});
if (req.readable) {
// Handles all the streamable data (e.g. image uploads)
req.pipe(redirectedRequest).pipe(res);
} else {
// Handles everything else
redirectedRequest.pipe(res);
}
});