Last active
July 23, 2018 12:56
-
-
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.
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
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