Skip to content

Instantly share code, notes, and snippets.

@arifmahmudrana
Created January 26, 2020 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arifmahmudrana/26df8f522d88e6199e5650c9a550a61e to your computer and use it in GitHub Desktop.
Save arifmahmudrana/26df8f522d88e6199e5650c9a550a61e to your computer and use it in GitHub Desktop.
Axios proxy request with express
axios({
method: 'get',
url: 'URL',
params: {
keyword: 'keyword'
},
responseType: 'stream'
})
.then(response => {
for (const key in response.headers) {
if (response.headers.hasOwnProperty(key)) {
const element = response.headers[key];
res.header(key, element);
}
}
res.status(response.status);
response.data.pipe(res);
})
.catch(({ response }) => {
for (const key in response.headers) {
if (response.headers.hasOwnProperty(key)) {
const element = response.headers[key];
res.header(key, element);
}
}
res.status(response.status);
response.data.pipe(res);
});
@mktcode
Copy link

mktcode commented May 29, 2021

Thanks man! Just what I needed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment