I am trying to pass back a url string as "data" into my eventhandler.
My request to the server is "https://172.20.10.6/index.html".
The console.log
below prints out "/index.html" as I expect.
switch(req.method) {
case 'GET':
console.log("logged from plugin-https.js: url: " + req.url);
ee.emit("dataIn", req.url);
break;
Below is the eventHandler code.
The console.log(data);
evaluates to "undefined". I am trying to figure out why this is. It seems like a pretty straightforward direct callback, so I am wondering why the data is not defined when it shows up in the eventhandling code.
plugin = rtrn;
console.log('4');
plugin.dataIn(config, function(err, data) {
if(err, data) {
console.log('error geting data');
} else {
// This is where request events are being handled.
console.log(data);
console.log('We are in the event handling codeblock of funtion startRuntime() located in interactor.js');
Also, here is my callback code
var ee = new events.EventEmitter();
function dataIn(config, callback) {
if(typeof callback === 'function') {
ee.on("dataIn", callback);
It looks like you're swallowing errors.
That condition
(err, data)
will ignore the value oferr
. Ifdata
is undefined, it will be falsy and you won't know that you had an error. You probably want something more like this:Tracing back to your emitter, you are emitting in a way that sends your data to the first argument, which should be where the error goes. So this:
...should be more like this: