var express = require("express");
var bodyParser = require("body-parser");
var cp = require('child_process');
var program = require('commander');

var registries = [ 'hexonet'];
var eppProcesses = {};
for (var accred in registries) {
    var registry = registries[accred];
    var eppProcess = cp.fork(__dirname + '/worker.js');
    eppProcess.send({
        "registry": registry
    });
    eppProcesses[registry] = eppProcess;
}
process.on('SIGINT', function() {
    var logoutResponse = function(data) {
        console.log("Got reply from logout: ", data);
    };
    for (var registry in eppProcesses) {
        var childProc = eppProcesses[registry];
        childProc.send({
            "command": "logout",
            "data": {}
        });
        childProc.on('message', logoutResponse);
    }
    process.exit(0);
});

var app = express();

app.use(bodyParser.json());

app.post('/command/:registry/:command', function(req, res) {
    //res.set('Content-type', 'application/json');
    if (! (req.params.registry in eppProcesses)) {
        res.send(400, {
            "error": "Unknown registry"
        });
        return;
        //res.end();
    }
    var registry = req.params.registry;
    var childProc = eppProcesses[registry];
    var queryData = req.body;
    childProc.on('message', function(m) {
        //res.write(m);
        res.end(m);
    });
    childProc.send({
        "command": req.params.command,
        "data": queryData
    });
});


app.listen('3000');


@@ -144,37 +144,369 @@
 );%0A%0A
-var registries = %5B 'hexonet'%5D
+function collectRegistries(val, registryArgs)%7B%0A    registryArgs.push(val);%0A    return registryArgs;%0A%7D%0A%0Aprogram.version('0.0.1').option('-r, --registries', 'Registry', collectRegistries, %5B%5D)%0A.option('-l, --listen', 'Listen on port', parseInt, 3000).parse(process.argv);%0A%0Aconsole.log(%22Passed regsitries: %22, program.registries);%0Avar registries = program.registries
 ;%0Ava
@@ -1812,14 +1812,22 @@
 ten(
-'3000'
+program.listen
 );%0A%0A

fix merge conflict