I\'m currently following the UI5 tutorial and am stuck on step 27: Mock Server Configuration.
The problem is the rootUri
configuration of the mock server. I
Some details of chapter 27 of the tutorial are quite misleading.
The rootUri
of the MockServer must match the uri
parameter of the datasource in manifest.json.
Instead of changing datasource's uri to the (wrong) rootUri
of MockServer given in the tutorial, you should actually change MockServer's rootUri
to the URI of the external source. In webapp/localService/mockserver.js
use this corrected block:
var oMockServer = new MockServer({
rootUri: "https://services.odata.org/V2/Northwind/Northwind.svc/"
});
This will create a MockServer that intercepts all calls to that external URI and responds to them locally. And with this construct, it is actually possible to access the MockServer through /webapp/test/mockServer.html
and the live data server through /webapp/index.html
.
Hint:
You will most likely still have trouble accessing the original (external) data source using /webapp/index.html
due to Same Origin Policy restrictions (SOP). With Google Chrome this can be nicely solved by running a second (!) instance of the browser without SOP. This is possible in parallel to other open browser windows of the standard instance WITH SOP, so you don't need to close all your open browser windows. See this answer for details.
There are some rules to watch out for when it comes to defining the rootUri
for mock server.
The rootUri
"/"
)It is mentioned in the step 27:
(The
rootUri
) matches the URL of our data source in the descriptor file.
As well as in the topic Mock Server: Frequently Asked Questions:
The root URI has to be relative and requires a trailing '/'. It also needs to match the URI set in OData/JSON models or simple XHR calls in order for the mock server to intercept them.
So it doesn't matter how your rootUri
is defined as long as it fulfills those three requirements mentioned above. That's why some arbitrary URIs like rootUri: "/"
works as well but only if the uri
in the dataSource is the same.
In your case, changing the rootUri
value like this below should make the mock server running:
var oMockServer = new MockServer({
rootUri: "/destinations/northwind/V2/Northwind/Northwind.svc/"
});
And in your app descriptor (manifest.json) respectively..:
"dataSources": {
"invoiceRemote": {
"uri": "/destinations/northwind/V2/Northwind/Northwind.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
}
}
To make the path work in a non-MockServer scenario, you'll need to register a corresponding destination in SAP Cloud Platform and edit neo-app.json in your project accordingly.
No need to change the application code.