-
-
Save ashthespy/784394a64601b095724a724694a512d6 to your computer and use it in GitHub Desktop.
Simple method to set additonal headders for webradios with Volumio and MPD
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
#!/usr/bin/env node | |
const http = require('http'); | |
const proxy_port = 2585; | |
http.createServer(onRequest).listen(proxy_port); | |
console.log(`Server up and listening on ${proxy_port}`) | |
function onRequest(client_req, client_res) { | |
let options; | |
switch (client_req.url) { | |
case '/tamilradios': | |
options = { | |
hostname: '212.47.243.160', | |
port: 8002, | |
path: '/1', | |
method: client_req.method, | |
headers: client_req.headers | |
}; | |
// Add the required header | |
options.headers.Referer = 'http://www.tamilradios.com' | |
break; | |
// This should be refactored! | |
default: | |
options = { | |
hostname: 'www.tamilradios.com', | |
port: 80, | |
path: client_req.url, | |
method: client_req.method, | |
headers: client_req.headers | |
}; | |
break; | |
} | |
const proxy = http.request(options, function(res) { | |
client_res.writeHead(res.statusCode, res.headers) | |
res.pipe(client_res, { | |
end: true | |
}); | |
}); | |
client_req.pipe(proxy, { | |
end: true | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment