RED.httpNode.get gives "Unauthorized"

Hi folks,

I have released last week the node-red-contrib-ui-heatmap node, which worked fine at the moment...

However I got a Github issue from somebody that cannot see the heatmap in his dashboard. So I have installed the heatmap-node myself from NPM on one my Raspberries, and indeed I cannot see it either.

But I see this in my console log:

image

This is my server side to publish the heatmap.min.js library:

RED.httpNode.get('/ui/heatmap/js/*',  RED.auth.needsPermission('heatmap.read'), function(req, res){
        var options = {
            root: __dirname + '/lib/',
            dotfiles: 'deny'
        };
       
        // Send the requested file to the client (in this case it will be heatmap.min.js)
        res.sendFile(req.params[0], options)
});

And this is my client side to load the third-party library:

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

Does anybody have any idea what could cause the authentication issue?

I also don't get why there is a very long number in the console log message (= 155199...).
Don't know why it worked fine last week ..

Thanks !!!
Bart

You should not be using the needsPermission middleware on RED.httpNode.

needsPermission is for the admin apis - in other words routes that are mounted on RED.httpAdmin.

Thanks Nick (@knolleary),

I have changed the code of my UI-widget nodet to this:

RED.httpNode.get('/ui/heatmap/js/*', function(req, res){
        var options = {
            root: __dirname + '/lib/',
            dotfiles: 'deny'
        };
       
        // Send the requested file to the client (in this case it will be heatmap.min.js)
        res.sendFile(req.params[0], options)
});

But then I still get this:

image

And indeed, I don't even arrive on my breakpoint in this code snippet ...

But the weird thing is that it works fine when I copy the SAME URL (from the browser console log) in the address bar of my browser:

image

Any ideas?

Have tried all kind of things (rebooted my Raspberry, cleared browser cache ...) and now suddenly it appears:

image

I will create a new version with your tip, and hopefully the issues are solved for everybody ...

I have installed the node of Heatmap with sample flow. But my question is that I do not know where to get the heatmap url?

myurl.com/ui ?

Please help. thanks!

Hello Howard (@howardweng),

The above discussion is about an url that I use internally in my heatmap node, so you don't need to bother about this. I assume you have installed the dashboard nodes? Then the heatmap widget should be visible in your Node-RED dashboard, which is running at http://<your_ip_address>:1880/ui (or https://<your_ip_address>:1880/ui if you have setup ssl).f

thanks for your reply. @BartButenaers , and sorry for not directly meet this topic for my question.

I know you are author of this good function node, thanks!

I did what you said, and I expect to see the heatmap in my /ui as dashboard chart did, but not happening.

here is my config. version. It will be good if you can help me to debug for this.

node-red
0.20.5
node-red-contrib-ui-heatmap
2.0.0
node-red-dashboard
2.15.2

simple flow:

[{"id":"b1cb294a.84a818","type":"heat-map","z":"5b9ab371.3a9f7c","group":"85148c3d.ed438","order":0,"width":"6","height":"5","name":"","rows":"20","columns":"10","minMax":false,"minimumValue":0,"maximumValue":0,"backgroundColor":"#ffffff","radius":"40","opacity":0.6,"blur":0.85,"x":610,"y":680,"wires":[]},{"id":"a2a437.33b32bc8","type":"function","z":"5b9ab371.3a9f7c","name":"Generate random matrix","func":"// Generate some random data\n// See https://www.patrick-wied.at/static/heatmapjs/example-minimal-config.html\nvar len = 200;\n\nmsg.payload = ;\n\nwhile (len--) {\n var value = Math.floor(Math.random()*100);\n msg.payload.push(value);\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":680,"wires":[["b1cb294a.84a818"]]},{"id":"aa26a036.f4c55","type":"inject","z":"5b9ab371.3a9f7c","name":"Show heatmap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":680,"wires":[["a2a437.33b32bc8"]]}]

if you can see node still have problem showing Heatmap node, when I replace with new node, and inject the array, nothing happening at /ui dashboard

https://github.com/howardweng/mk100/blob/master/test/heatmap_problem1.jpg

@howardweng,
P.S. Your jpg image link isn't valid (i.e. there is no image available).

I see that there is a syntax error in your function node:
image

Could it be that you have accidentally removed that by yourself? When I import my original heatmap example flow via the Node-RED menu, then the function node is correct:

msg.payload = [];

The heatmap can only be drawn when you inject values into it. So when you press your Inject node's button, your function node cannot fill the message payload with numbers (due to the syntax error), so no heatmap is drawn ...

After adding [], it seems to work correctly.
I have specified to show it here in the dashboard tree:

image

And it indeed appears at that position in my dashboard:

image

When you start next time with your own new discussion in this forum, most likely you will get more help from the rest of the community. Some users (that are more experienced with this kind of issues) might not read "development related discussions" like this one.
Bart

1 Like