Constant Disconnection

121 views
Skip to first unread message

Justin Scott

unread,
Jan 18, 2016, 1:30:54 PM1/18/16
to Node-RED
Here is an odd error I have after integrating the Node-RED Version 0.13.0 into an existing express 4 app. Skeleton is based off Sahat Hackathon Boilerplate. Middleware and CSRF I am bypassing while integrating this piece by piece. Issue at hand:

I keep getting a "Error: Lost connection to server" after using the UI for a few seconds. Traced back with dev tools to this error on WebSockets:

WebSocket connection to 'ws://localhost:3000/red/comms' failed: Connection closed before receiving a handshake response red.min.js:16

Any ideas on what may be causing the issue? Replicated it both on a Windows machine I develop on and a Linux Ubuntu server cloud I test/produce on. Need more details I can try to dig them up as well. 

Nicholas O'Leary

unread,
Jan 18, 2016, 1:33:35 PM1/18/16
to Node-RED

Depends on how you're integrating it with your existing app. Did this work with a previous Node-RED version or is this first time you've tried?

Can you share (off list if you want) your code that initialises and starts Node-RED?

Nick


--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Scott

unread,
Jan 18, 2016, 1:40:36 PM1/18/16
to Node-RED
First time as I was waiting on the 0.13 release before doing this. 


///////////////////////////
// Start Express Server //
/////////////////////////
var server = http.createServer(app);
app.listen(app.get('port'), function() {
console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env'));
});


////////////////////////
// NodeRed Implement //
//////////////////////
var RED = require("node-red");

var settings = {
httpRoot: '/red',
userDir:"~/.nodered/",
uiPort: 3000,
nodesDir: '~/.nodered/nodes',
functionGlobalContext: { } // enables global context
};

RED.init(server,settings);

// Serve the editor UI from /red
app.use('/red', RED.httpAdmin);

// Start the runtime
RED.start();

Everything else is standard to doing express. Only hiccup I had was not declaring server which is corrected before-hand.  

RED.httpAdmin is not in settings file. Loads fine with that but when changed to RED.httpRoot I get the following:

      throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
      ^

Ideally I would like to configure all this to be setup like so:

exports.index = function(req, res) {
res.render('home', {
title: 'Home'
});
};

Like to run the UI within an extended JADE block if possible. Kind of a two part question now. Slice the other part in to another question if needed. 

Nicholas O'Leary

unread,
Jan 18, 2016, 2:45:55 PM1/18/16
to Node-RED Mailing List
Hi,

in the embedding case, you must provide both httpAdminRoot and httpNodeRoot - the httpRoot is a convenience setting used by the wrapper that launches the stand-alone node-red application to set httpAdminRoot/httpNodeRoot before they are passed to the runtime.

The docs will get better, I promise.

Nick

Justin Scott

unread,
Jan 18, 2016, 4:51:41 PM1/18/16
to Node-RED
Still getting a weird error when trying to embed this.

// Serve the editor UI from /red
app.use(settings.httpAdminRoot, RED.httpAdminRoot);
app.use(settings.httpNodeRoot, RED.httpNode);

 Trace:

      throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
      ^

TypeError: Router.use() requires middleware function but got a undefined
    at Function.use (C:\Ignite\node_modules\express\lib\router\index.js:458:13)
    at EventEmitter.<anonymous> (C:\Ignite\node_modules\express\lib\application.js:219:21)
    at Array.forEach (native)
    at EventEmitter.use (C:\Ignite\node_modules\express\lib\application.js:216:7)
    at Object.<anonymous> (C:\Ignite\app.js:176:5)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:136:18)
    at node.js:963:3

Anything here I am still missing on trying to get this to work?  

Nicholas O'Leary

unread,
Jan 18, 2016, 4:54:25 PM1/18/16
to Node-RED Mailing List
That first line should be:
    app.use(settings.httpAdminRoot,RED.httpAdmin);



Justin Scott

unread,
Jan 18, 2016, 4:57:39 PM1/18/16
to Node-RED
Still no luck changing that. Final jab after that fix with all the goodies here:

////////////////////////
// NodeRed Implement //
//////////////////////
var RED = require("node-red");

var settings = {
    httpAdmin:'/red',
httpNode: '/api',

userDir:'~/.nodered/',
uiPort: 3000,
nodesDir: '~/.nodered/nodes'
};

// Serve the editor UI from /red
app.use(settings.httpAdmin,RED.httpAdmin);
app.use(settings.httpNode,RED.httpNode);

RED.init(server,settings);


// Start the runtime
RED.start();

Nicholas O'Leary

unread,
Jan 18, 2016, 4:59:14 PM1/18/16
to Node-RED Mailing List
You need to call RED.init before you can use RED.httpAdmin / RED.httpNode


Justin Scott

unread,
Jan 18, 2016, 5:02:16 PM1/18/16
to Node-RED
That did the trick! Any ideas on the Websocket error from the top of the post? Still am receiving the message in my Dev Tools on Chrome

red.min.js:16 WebSocket connection to 'ws://localhost:3000/red/comms' failed: Connection closed before receiving a handshake response

Could this be a firewall related issue? Running all locally on my machine.
Reply all
Reply to author
Forward
0 new messages