简体   繁体   中英

How to include another SAP Cloud project resource into deployed SAPUI5 app?

I created several SAPUI5 web applications in Eclipse that have been deployed to a SAP NetWeaver PO 7.5 Application Server.

All these applications use generic components of a "common" project. I just made them available via the html header with this bootstrapping script-tag:

<!-- Bootstrapping UI5 -->
<script id="sap-ui-bootstrap"
        src="/sapui5/resources/sap-ui-cachebuster/sap-ui-core.js"
        data-sap-ui-libs="sap.m"
        data-sap-ui-theme="path.to.custom.theme"
        data-sap-ui-compatVersion="edge"
        data-sap-ui-resourceroots='{"com.namespace.ui.specificapp": ".", "com.namespace.ui.common" :"/com.namespace~ui~common~web"}'
        data-sap-ui-frameOptions="trusted"
        data-sap-ui-appCacheBuster = "./,/com.namespace~ui~common~web/" >
</script>

This worked fine until I tiered to transfer these applications to SAP Cloud.

I imported the projects to WebIDE and first thing I discovered was that data-sap-ui-resourceroots attribute doesn't work anymore because application cannot find the components from the common project. So I deployed the common application to SAP Cloud and inserted the corresponding URL in the bootstrapping script-tag of the index.html like this:

<script id="sap-ui-bootstrap"
    src="/sapui5/resources/sap-ui-cachebuster/sap-ui-core.js"
    data-sap-ui-libs="sap.m"
    data-sap-ui-theme="path.to.custom.theme"
    data-sap-ui-compatVersion="edge"
    data-sap-ui-resourceroots='{"com.namespace.ui.specificapp": ".", "com.namespace.ui.common" :"/https://common-aXXXXXXXX.dispatcher.hana.ondemand.com/"}'
    data-sap-ui-frameOptions="trusted"
    data-sap-ui-appCacheBuster = "./,/com.namespace~ui~common~web/" >

This allows browser to find the JS-files from the common project, but leads to this error:

Note: Your browser does not support JavaScript or it is turned off. Press the button to proceed.

This is message is thrown by the https://common-aXXXXXXXX.dispatcher.hana.ondemand.com/ host.

Analysing the HTTP request I see that the parameter Accept:text/plain, */*; q=0.01 Accept:text/plain, */*; q=0.01 is set.

I don't know why SAPUI5 is requesting plain text or where I can change this behavior. Does anyone know how to tranfer this application structure to the SAP Cloud?

The answer is pretty easy: The server blocks requests to other origins to prevent CSRF attacks. In the on premise solution all source files come from the same origin: the own server. In the SAP Cloud each application is deployed standalone with its own URL. Therefore the browser doesn't accept JavaScript files from other projects. The solution to access these files is to add the URL of the common project to the destinations in the SAP Cloud Cockpit.

FYI : Including the URL in the destinations enables you to use a relative URL for referring to external JavaScript files, so that they aren't blocked by the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM