Created
July 25, 2019 13:19
-
-
Save stormoz/4c055377eebcdf6613387ef66664620d to your computer and use it in GitHub Desktop.
read data to stream
This file contains 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
import http from 'http'; | |
import axios from 'axios'; | |
http.createServer(async function (req, res) { | |
const responseStream = await axios({ | |
method: 'get', | |
url: 'http://blob.file.storage/filepath', | |
responseType: 'stream' | |
}); | |
const contentType = responseStream.headers['content-type']; | |
const contentLength = responseStream.headers['content-length']; | |
res.writeHead(200, { | |
'Content-Type': contentType, | |
'Content-Length': contentLength | |
}); | |
responseStream.data.pipe.pipe(res); | |
}).listen(2000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment