How can I configure manifest.json file so when I run mockserver(mockserver.html) then it goes to the local json data and when I run index.html (main entry to application) then it goes to the remote service. I have a sample manifest.json file from the documentation but not very clear how remote and local service come into play.
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "xxx",
"type": "application",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"mainService": {
"uri": "https://services.odata.org/V2/Northwind/Northwind.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": [
"sap_hcb",
"sap_bluecrystal"
]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView": {
"viewName": "xxx.view.Main",
"type": "XML"
},
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"config": {
"productLocal": "localService/mockdata/products.json",
"productRemote": "/some remote end point"
},
"products": {
"dataSource": "mainService"
}
}
}
Controller code
var oModel = new sap.ui.model.odata.ODataModel("/", true);
//var data = oModel;
//console.log(data);
var inputModel = new JSONModel("../model/inputs.json");
var productsModel = new JSONModel();
oModel.read("/ProductSet",
null,
null,
false,
function _OnSuccess(oData, response) {
console.log(oData);
console.log(response);
var data = {"ProductCollection" : oData.results};
productsModel.setData(data);
},
function _OnError(error) {
console.log(error);
});
//set model(s) to current xml view
this.getView().setModel(inputModel, "inputModel");
this.getView().setModel(productsModel);
Thanks for the help.
You don't need to touch
manifest.json
file for mocking the service. In fact, inmanifest.json
the property of dataSources-localUri
: takes relative URL to local metadata document or annotation uri. Not for the service.I hope your
mockserver.html
looks like this:You can define your mock server as below:
Read complete steps here