RED.httpNode.get gives "Unauthorized"

#1

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

0 Likes

#2

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.

0 Likes

#3

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?

0 Likes

#4

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 ...

0 Likes