-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
27 lines (21 loc) · 836 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var argv = require('optimist').argv;
var virsh = require('child_process').spawn('virsh', [ '-c', argv.c || 'lxc://', 'list']);
virsh.stdout.on('data', function(data) {
var matches = data.toString().match(/\d+\s+\S+\s+[^\n]+/gm);
if (!matches)
return console.log('No libvirt domains found');
var domains = matches.map(function(line) {
var domain = line.split(/\s+/);
return domain[1];
});
var hostname = argv.h || require('os').hostname();
var port = argv.p || 80;
var options = { router: { } };
domains.forEach(function(dom) {
var from = dom.replace('.', '-') + '.' + hostname;
options.router[from] = dom;
});
console.log('Starting reverse proxy on', hostname, 'port', port);
console.log('Routing table:', options.router);
require('http-proxy').createServer(options).listen(port);
});