Skip to content

Instantly share code, notes, and snippets.

@raym
Last active July 23, 2018 12:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raym/2bfa72ef9ce3125a528c1cef57c1332b to your computer and use it in GitHub Desktop.
Save raym/2bfa72ef9ce3125a528c1cef57c1332b to your computer and use it in GitHub Desktop.
Stream/proxy/pipe an mp3 file using express node.js web app framework.
var
_ = require('underscore'),
https = require('https'),
express = require('express'),
app = express()
;
app.get('/audioFile.mp3', function(req, res) {
https.get('https://example.com/any-mp3-file.mp3', function(audioFile) {
res.set(_.extend(_.pick(audioFile.headers, 'accept-ranges', 'content-type', 'content-length'), { 'Access-Control-Allow-Origin': '*' }));
audioFile.pipe(res);
}).on('error', function(err) {
console.error(err);
}).end();
});
var server = app.listen(3000, function () {
console.log('app listening on port %s', server.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment