Created
January 26, 2020 11:28
-
-
Save arifmahmudrana/26df8f522d88e6199e5650c9a550a61e to your computer and use it in GitHub Desktop.
Axios proxy request with express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks man! Just what I needed. :)