httprequestnode-rednode-request

node red cannot GET /myfile from directory


I would like to ask.

I have file in C:\users\nxf68958\.Node-red\report.html

And when I would like to open this file by: localhost:1880/report.html I get: Cannot GET /report.html

in Log I have: "Nov 09:52:00 - [info] User directory : \Users\nxf68958\.node-red"

I am using: NR: 3.0.2 Node: 18.12.0

It worked perfectly on older versions of: NR: 2.2 and Node: 16.13. Then I actualized and it stopped working.

In settings.js is option: "fileWorkingDirectory" I tried to change it, but without change. What I am doing wrong?

Thank you


Solution

  • Node-RED will not serve static files by default, you have to explicitly enable it by settings the httpStatic option in the settings.js file.

    Settings the httpStatic value to point to the userDir (which is what you have basically done by setting it to __dirname) is a bad idea from a security point of view because this means anybody can download your flows.json and flows_creds.json files and the files like settings.js and .config.runtime.json (which holds the default encryption key for the creds file).

    fileWorkDirectory is purely to set the default working directory for the code nodes that interact with the filesystem, it will have no effect on what files are served by the HTTP server.