Add middleware for static contents

Hello everyone,

Here is my context:

We would like to use node-red server as an intermediate layer, for accessing private files.

For POC purpose, we added a simple http GET file route under nodered, in order to check and validate the input token from url params. And we read and send back a local file, such as suggested in
https://cookbook.nodered.org/http/serve-a-local-file

The whole mechanism works fine, but to read and send back a file buffer object seems to be slow.
If we need to show contents (video) in a real time conversation, this solution seems inadaptable.

Questions:

  • Is there any alternative solutions or mechanisms for facilitating this kind of file download process ?
  • I was thinking about using the static folder, since it’s much more faster. But can we add a token validation middleware before access to static folder ? (I've tested the httpNodeMiddleware, but if I understand well, it's only for normal routes)

Thank you very much

You can easily check whether httpNodeMiddleware by adding a custom header, restarting Node-RED and doing a full reload of a static resource (to clear any caching).

Assuming that doesn't work, you could probably abuse uibuilder to do what you want as that certainly does have a middleware feature that should apply to all resources (I think, I tend to loose track of some of the more esoteric features :sunglasses:). I can probably tweak it anyway if something specific is needed.

2 Likes

(Haha, thanks for advice, i'm gonna test it for my personal projects later :grin:)

I checked the code from NodeRed, seems no more than basic auth middleware can be used. I'm wondering whether I should create a node red component for this.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.