Skip to content

Instantly share code, notes, and snippets.

@ashthespy
Created August 27, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashthespy/784394a64601b095724a724694a512d6 to your computer and use it in GitHub Desktop.
Save ashthespy/784394a64601b095724a724694a512d6 to your computer and use it in GitHub Desktop.
Simple method to set additonal headders for webradios with Volumio and MPD
#!/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