Julian (@TotallyInformation) and I had a similar discussion just a few months ago, as I was looking for a simple way to serve my stand-alone nodejs application's UI and API endpoints from node-red. It was dead simple to set up a new ui_builder
root node (i.e. as /myapp
), check out the myapp repo into the uibuilder directory, and serve all the front-end pages as '/myapp/ui/index.js'.
The tricky part for my use case was that I already had dozens of back-end rest apis defined as express routes on a separate port in 'api.js'. Julian showed me how to add those to an express router function, which could be added to ui_builder, and effectively served as '/myapp/api/xxx' endpoints -- just what I needed! And I suspect would work for your situation as well. By the way, I would suggest that you do not use the same root url for both front-end UI and back-end API calls.
The unfortunate thing is that all of this work was done in the vnext branch, which is not due for public release any time soon. Perhaps when he gets back from holiday, we can help him debug an alpha version of code...