Can I "host" stand-alone nodejs apps inside UIBuilder nodes? If so, should I?

Hey Julian - thanks for the thoughtful answers...

I hope you know by now that I'd love to be able to do as much of my work in Node-RED as possible -- but in this case there are dozens of APIs already written in a stand-alone express app, utilizing a new instance of express with routes set up like so...

const app = express();

app.get('/api/ping', (req, res) => {
    res.json({ success: true });
});

// Get Custom Settings
app.get('/api/custom-settings', (req, res) => {
    console.info('GET custom-settings');
    sessionService.getCustomSettings(req, res);
});
// Save Custom Settings
app.post('/api/custom-settings', (req, res) => {
    console.info('POST custom-settings');
    sessionService.saveCustomSettings(req, res);
});

... yada yada -- dozens of api call later ...

app.listen(API_PORT, () =>
    console.info(`API Server started @ http://${API_HOST}:${API_PORT}/api`)
).setTimeout(180000); // Max connection time of 3 minutes

Notice how the first step is to instanciate an express app, and the last step is to start it running...
The other 90% of the middle of the api.js existing code is what I'd like to be hosted relative to the existing route added based on the uibroot url. Preferably without rewriting it all as node-red flows. It seems analogous to the way you pass your Vue app into uibuilder, but I admit that I'm a bit confused by how all of that just "works".

I think what I'm asking for is a way to graft my pure nodejs api code into the uibuilder backend -- then, going forward, I can migrate existing apis into node-red flows as needed. Perhaps using a technique like you do in the middleware checking code:

        //#region ----- Set up ExpressJS Middleware ----- //
        /** Provide the ability to have a ExpressJS middleware hook.
         * This can be used for custom authentication/authorisation or anything else.
         */
        var httpMiddleware = function(req,res,next) { next() }
        /** Check for <uibRoot>/.config/uibMiddleware.js, use it if present. Copy template if not exists @since v2.0.0-dev4 */
        let uibMwPath = path.join(uib.configFolder, 'uibMiddleware.js')
        try {
            const uibMiddleware = require(uibMwPath)
            if ( typeof uibMiddleware === 'function' ) {
                httpMiddleware = uibMiddleware
            }    
        } catch (e) {
            log.trace(`[uibuilder:${uibInstance}] uibuilder Middleware failed to load. Reason: `, e.message)
        }

I tried putting some code to check if the req.path starts with "/api/", but since that runs with every request, it's not really scalable. Anyway, if this whole discussion goes against what uibuilder is trying to do, I can probably find another way. There just seems to be so much in place that I could use, with some clever packaging...

Steve