Custom UI node cannot access changed path

Hi folks,

Got an issue on Github for my node-red-contrib-ui-heatmap node. After some discussions and digging into the code, it seems there are a few things incorrect in my node, but I'm running out of ideas ...

This is the second problem:

My heatmap UI widget tries to load a javascript library heatmap.min.js (from the Node-RED server):

<script src="heatmap/js/heatmap.min.js"></script>

The server side will return the heatmap.min.js as soon as a request arrives:

RED.httpNode.get('/ui/heatmap/js/*', function(req, res){

In my case this works fine, but the other user's dashboard couldn't load the case:

  • In my case the request is http://.../ui/heatmap/js/heatmap.min.js, which matches the required pattern and the file is loaded without problems.
  • In the user's case the request is http://.../dashboard/heatmap/js/heatmap.min.js which doesn't match, so it will never be redirected to the request handler...

The cause seemed to be that the user had changed the path (in the settings.js file) to 'dashboard' instead of 'ui':

// If you installed the optional node-red-dashboard you can set it's path
// relative to httpRoot
//ui: { path: "ui" },

Is there an easy way to support such custom paths? Should I remove the 'ui' from my path, or should I load the path from the settings and use it in my path automatically, or ... ?

Thanks !
Bart

can't recall right this sec - but I think you have access to the RED.settings object so hopefully you may be able to grab the value you need.

2 Likes

@dceejay,
Don't be so modest...
I can now confirm your brain is still functioning very well after all those long years :brain:

  • By default the ui-path setting is in comment (in the settings.js file), and then I receive an undefined:

    image

  • And as soon as I specify my own path, it indeed becomes available:

    image

So I use it now like this:

var uiPath = ((RED.settings.ui || {}).path) || 'ui';
RED.httpNode.get('/' + uiPath + '/heatmap/js/*', function(req, res){
   ...
}

Thanks a lot !!!

Tada ! - oh yes if not declared you would have to default it somehow... :face_with_head_bandage: