UI5 Mock Server with Local Data: “rootUri” Not Working

前端 未结 2 1483
感情败类
感情败类 2021-01-24 22:33

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

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 23:18

    There are some rules to watch out for when it comes to defining the rootUri for mock server.

    The rootUri

    • Should be relative
    • Has to end with a slash ("/")
    • Has to match with the URI that is assigned to your model.

    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.

提交回复
热议问题