Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading extra resources for application #23

Open
ghost opened this issue Jan 5, 2023 · 2 comments
Open

Loading extra resources for application #23

ghost opened this issue Jan 5, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2023

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.

@goodartmr
Copy link

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"));

@Macimaj95
Copy link

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"],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants