Basic proxy to Graphite
var httpProxy = require('http-proxy');
var re = /\/graphite(\/.*)/;
httpProxy.createServer(function (req, res, proxy) {
var match;
if ((match = re.exec(req.url))) {
console.log('Rewriting req.url to ' + match[1]);
req.url = match[1];
return proxy.proxyRequest(req, res, {
port: 9000, // CHANGE TO GRAPHITE PORT
host: 'wtf-graphite-frontend-host', // CHANGE TO DJANGO FRONT-END,
});
}
console.log('Non graphite traffic');
res.writeHead(500, { 'Content-Type': 'application/json' });
res.write(JSON.stringify({ error: 'not implemented' }));
res.end();
}).listen(8080);
console.log('Proxying graphite traffic at http://localhost:8080')