Loading extra resources for application
Opened this issue · 2 comments
Hello, at start I would like to thank you for developing this template.
I'm trying to make my first app that will work on a computer without internet access, however to draw graph i use node-red-node-ui-vega which unfortunately fetches data from CDN.
Fortunately in Node-RED if a module has a directory called resources at the top level, the runtime will make anything in that directory available to the editor under the url /resources// https://nodered.org/docs/creating-nodes/resources.
So i save source from CDN as .js files and place them in resources folder. Everything works great when i run node-red from terminal, I have acces to files like http://localhost:1880/resources/node-red-node-ui-vega/vega-cdn.js ect.
But when I build app or try it by yarn start i get Cannot GET /resources/node-red-node-ui-vega/vega-cdn.js even though i have access to editor and UI on app port(18880 set in main.js).
Has anyone encountered a similar problem or can give me some guidance.?Thanks in advance.
Same problem here.
I also have tried to load resources with httpStatic attribute in main.js.
Without success. When I start by yarn I get error message.
My solution:
Change line 60 of main.js to
red_app.use("/",express.static(__dirname +"/resources"));
Hello,
thanks for the idea goodartmr.
I put the files downloaded from the CDN in a folder called "external" in the main directory and in main.js I make the following change:
red_app.use('/external', express.static(path.join(__dirname, 'external')))
In addition, to package the application, you need to add a fragment in the package.json file
"files": [
<...>
{
"from": "external",
"to": "node_modules/@node-red/external"
}
]
as a result, the resources should be available as below:
loadScripts(["/external/node-red-node-ui-vega/vega-cdn.js",
"/external/node-red-node-ui-vega/vega-lite-cdn.js",
"/external/node-red-node-ui-vega/vega-embed-cdn.js"],