SAPUI5: Consider proxy in Mock Server Configuration

If you use a proxy server for your local SAPUI5 development, then do not forget to adjust the rootURI of the mock server configuration as well. The rootURI of the mock server configuration must be exact the same as the data source uri of the manifest.json.

SAPUI5 App: Running mockServer.html
SAPUI5 App: Running mockServer.html

While I was executing “Step 27: Mock Server Configuration” of the SAPUI5 Walkthrough-Tutorial, I ran into the issue that the Northwind OData Service was loaded instead of the mock data, and I spent some time to find my mistake.

Data source URI of manifest.json

Unfortunately, I did the step 27 two weeks after the remote OData Service (step 26) and had forgotten that I adjusted the data source URI of the manifest.json. By the way, this adjustment due to the CORS trouble led to my blog post “CORS: Proxy server for remote OData Service in local SAPUI5 Dev“.

"dataSources": {
        "invoiceRemote": {
        "uri": "http://localhost:8081/https://services.odata.org/V2/Northwind/Northwind.svc/",
        "type": "OData",
        "settings": {
          "odataVersion": "2.0"
          }
        }
      }

Furthermore, I read this sentence of the description of step 27 too fast: “The init method creates a MockServer instance with the same URL as the real service calls.” – and it is clear that same URL really means same URL.

So, when you use a proxy URL in the data sources, then you need to use this URL in the rootURI of the mock server configuration as well. The mock server will process each request that match the rootURI. If the rootURI is no the same as the data source URI, then there will be never a match.

var oMockServer = new MockServer({
				rootUri: "http://localhost:8081/https://services.odata.org/V2/Northwind/Northwind.svc/"
			});

Leave a Reply

%d bloggers like this: