I’m not sure, if I understood your setup correctly…
Do you fetch the data via REST API or do you include the cockpit bootstrap file via php?
Did you setup everything under example.com/cockpit, tested everything on example.com/cockpit/frontend and then changed example.com to point to /cockpit/frontend? In this case, cockpit is not public available anymore, but you should be able to include the bootstrap file.
Maybe with setting RewriteBase, but I have a setup on strato, where I didn’t need to change it.
You can change some constants for path detection if you add a file defines.php to the cockpit root folder.
I use the structure /frontend/cockpit, so the setup is a bit different, but maybe you can fiddle with it. Here are some threads with examples for the defines file: