The problem is that the question is based on a flawed premise, and answering it would mean saying "you are doing it wrong, there are other ways of doing it correctly but you'd have to rewrite a lot of your application, and the specifics of how to rewrite it would be too broad and opinion based for our Q&A format".
You are trying to:
use a client application running on the end-users's machine (what you call a "native" application in your question) to run a web server (what you call "a localhost server")
serve HTML on a different web server which is consumed by a different client application (the web browser), which in turn triggers AJAX requests to the original client application running on the end-user's machine
This is uniquely wrong, and answers (such as mine here), are bound to be very broad, impractical and opinionated. This stems from a poor design, and it seems you are not going to be convinced that your design is wrong and that you should rethink it.
If the client application needs information from the remote web server it should request it. Either by making its own HTTP requests, or by some sort of "subscriber" system if you need server initiated events. Think websockets or something like Mercure.
If you do not need to react to server-side-events, and instead you just want to react to user-initiated-events (which would explain the AJAX approach, where you simply are hosting the client remotely and the server locally), then the better approach would be to simply host the client on the same client application that hosts the local web server. HTML, JavaScript and API would all be on the same server, which would eliminate all the CORS and mixed contents problems and everything work fine, although probably on a non-standard port (e.g. http://localhost:19898
). Yours wouldn't be the first application to use this approach.
When a question is based on a basically wrong approach, and the path to fixing the correct approach would require a big architectural rethink and rewrite, the question can be too much for a site like this.