Skip to Content
0
Jun 20, 2018 at 02:25 PM

Accessing SAPUI5 resources on an OnPremise System

344 Views Last edit Jun 21, 2018 at 07:11 AM 6 rev

Hi SAPUI5-Supporters,

there is the Application Descriptor File (neo-app.json) to configure a SAPUI5-App in a SAP Cloud Platform environment. We use the neo-app.json for accessing other SAPUI5-Apps (App A access resources from App B and App C):

{
...
  "routes": [
...
    {
      "path": "/external/appB",
      "target": {
        "type": "application",
        "name": "appB",
        "entryPath": "/folder"
      },
      "description": "App B"
    },
    {
      "path": "/external/appC",
      "target": {
        "type": "application",
        "name": "appC",
        "entryPath": ""
      },
      "description": "App C"
    },
...
}

In the case of App B we use the entryPath attribute to define a specific folder in the other app to correctly resolve namespaces, when we call jquery.sap.registerModulePath (API).

Currently we are deploying these apps on an OnPremise System. We implemented an algorithm to determine, whether the code is running in CP or OnPremise.

jQuery.example = {
	makeModulePath: function(oParams) {
		if (!oParams.sEmbeddingNamespace || !oParams.sCloudModulePath || !oParams.sOnPremiseAppName) {
			throw new Error("Missing config! sEmbeddingNamespace, sCloudModulePath and sOnPremiseAppName are required.");
		}
		var sResult;
		var sPath = window.location.pathname;
		var iUI5Offset = -1;
		if ((iUI5Offset = sPath.indexOf("/ui5_ui5/")) !== -1) {
			// we are most likely on premise
			var sModulePath = sPath.substring(0, iUI5Offset + "/ui5_ui5".length);
			sResult = sModulePath + oParams.sOnPremiseAppName;
		} else {
			// we are most likely in a cloud environment
			sModulePath = jQuery.sap.getModulePath(oParams.sEmbeddingNamespace);
			if (sModulePath === ".") {
				sResult = oParams.sCloudModulePath;
			} else {
				sResult = sModulePath + oParams.sCloudModulePath;
			}
		}
		return sResult;
	},
	registerModule: function(oParams) {
		jQuery.sap.registerModulePath(oParams.sModuleName, jQuery.example.makeModulePath(oParams));
	}
};


jQuery.example.registerModule({
	sModuleName: "name.space.appB",
	sEmbeddingNamespace: "name.space.appA",
	sCloudModulePath: "/external/appB",
	sOnPremiseAppName: "/namespace/appB"
});
jQuery.example.registerModule({
	sModuleName: "name.space.appC",
	sEmbeddingNamespace: "name.space.appA",
	sCloudModulePath: "/external/appC",
	sOnPremiseAppName: "/namespace/appC"
});

When we start App A, paths to resources from App C are correctly resolved. Those for App B are not and App A crashes. As it seems, there is no Application Descriptor File for this scenario to define an entryPath.

How can we access SAPUI5 resources the same way, we do it in CP?

Thanks in advance and best regards,

Christian.