github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/containers/compilers/rump/nodejs/node-wrapper/node-wrapper-ec2.js (about)

     1  process.chdir('/tmp');
     2  
     3  var StdOutFixture = require('./fixture-stdout.js');
     4  var stdOutFixture = new StdOutFixture();
     5  
     6  //set up log server
     7  var _log = [];
     8  stdOutFixture.capture( function onWrite (string, encoding, fd) {
     9    _log.push(string);
    10    return true;
    11  });
    12  var StdErrFixture = require('./fixture-stderr');
    13  var stdErrFixture = new StdErrFixture();
    14  stdErrFixture.capture( function onWrite (string, encoding, fd) {
    15    _log.push(string);
    16    return true;
    17  });
    18  
    19  const PORT=9967;
    20  var http = require('http');
    21  function serveLogs(request, response){
    22      response.end(_log.join(""));
    23  }
    24  var server = http.createServer(serveLogs);
    25  server.listen(PORT, function(){
    26      console.log("Log server started on: http://localhost:%s", PORT);
    27  });
    28  
    29  console.log("unik v0.0 boostrapping beginning udp broadcast...");
    30  tring = require('querystring');
    31    var options = {
    32      hostname: "169.254.169.254",
    33      path: '/latest/user-data',
    34      method: 'GET',
    35    };
    36    var req = http.request(options, function(res) {
    37      console.log('Status: ' + res.statusCode);
    38      console.log('Headers: ' + JSON.stringify(res.headers));
    39      res.setEncoding('utf8');
    40      res.on('data', function (body) {
    41        console.log('Response: ' + body);
    42        env = JSON.parse(body);
    43        Object.keys(env).forEach(function(key) {
    44          var val = env[key];
    45          process.env[key] = val;
    46          console.log("Set env var: "+key+"="+val)
    47        });
    48        console.log("unik v0.0 boostrapping finished!\ncalling main");
    49        //CALL_NODE_MAIN_HERE
    50      });
    51    });
    52    req.end();