Is there Standard Way of Obtaining OpenMRS Context Path in OWAs?

I am working on a new OWA module using angular. I was wondering whether there is a standard way of obtaining the OpenMRS context path. To avoid confusion by context path I mean the portion “openmrs” in the URL http://localhost:8080/openmrs.

I was thinking of getting the entire URL, then extracting the substring starting from third ‘/’. I am sure in most cases this would work, however this does not feel right, for one, some people may decide to deploy the application in root context or behind a proxy.

One simple way to solve this would be to introduce an OWA global property, this can be tricky too if the server is behind a reverse proxy like nginx but at least if the administrator is aware they can change the value to reflect the proxy’s configurations.

Any thoughts? Or rather how are people handling this?

See what is written about appBaseUri in the readme for https://github.com/openmrs/openmrs-module-owa

You can do something like

$.getJSON( "manifest.webapp", function( json ) {
    var apiBaseUrl = json.activities.openmrs.href + "/ws/rest/v1";
} );

Is this file dynamically generated when the owa is installed? Besides I was wondering whether there is a standard way of doing this. This seems to me like a very standard thing to do in owa to be left to the developer to make a decision of what would work.

I believe the file is modified/generated when the OWA is uploaded, but you could check the OWA module code to be sure.

What I shared is the standard way to get the bar URL of the currently running OWA. I would be interested if you can suggest a way to make this easier to access without being the idea that OWA content is all static web files (and this cacheable, etc). Because I also think it’s annoying to have to make an http call to know this key detail.