Http endpoint guidelines

Hi folks,

The config screen of my node-red-contrib-blockly node needs to load a series of Javascript library files from the server. This is implemented by using a http endpoint:

RED.httpAdmin.get('/blocky/js/*', function(req, res){
   ...
}

I have always thought this was the correct way of working, since you can find following explanation in the Node-RED cookbook:

Sometimes a custom node needs to be able to look up additional data at configuration time (e.g. when editing the configuration of a node instance in the admin interface).
The approved way to do this is for the node to register an extra http endpoint to use as an API.

However today an issue is raised for my blockly node:

Node doesn't show the blockly editor control when custom httpAdminRoot in use.

I have never used the httpAdminRoot setting, but seems that it allows you to disable all admin endpoints (both API endpoints and the editor UI). So I assume that my endpoint is disabled => no .js files are loaded => the blockly editor is not displayed...

Does anybody have a clue how I can solve this?

Thanks !!!
Bart

If you disable httpAdminRoot then nothing will load in the editor at all because the admin api has been disabled.

The issue is how you are loading it from the browser side: https://github.com/bartbutenaers/node-red-contrib-blockly/blob/master/blockly.html#L21-L33

Long story short, remove the / from the front of all those urls so the browser loads them relative to where the editor was loaded from rather than as an absolute path from the root of the domain.

On the wiki page you link to, you'll note this is spelt out in the very last bullet point on the page.

Nick

Thanks Nick, sounds logical. Will give that a try!

In uibuilder, I make sure I use RED.settings.httpNodeRoot in the URL so this doesn't happen. Something like the following example:

$('#uibuilderurl').empty().append('<a href="' + RED.settings.httpNodeRoot + $(this).val() + '">' + RED.settings.httpNodeRoot + $(this).val() + '</a>')
1 Like

@TotallyInformation: Will keep it in mind for my next node. Wasn't aware about the existence of something like httpAdminRoot ...

1 Like