현재 UI5 tutorial을 따라 잡고 있으며 step 27 : Mock Server Configuration에 머물러 있습니다.로컬 데이터가있는 모의 서버 UI5 : "rootUri"가 작동하지 않습니다.
문제는 모의 서버의 rootUri
구성입니다. 튜토리얼에 따라 Northwind OData service을 사용하고 송장에 대해 dataSource
을 manifest.json
으로 구성했습니다.
이제 온라인 서비스 대신 로컬 모의 데이터를 사용하기 위해 튜토리얼에서 설명한대로 필요한 파일을 만들었습니다. mockServer.html
을 실행하면 서버가 서비스 요청을 로컬 모의 데이터로 리디렉션하지 않고 웹 보안 문제로 인해 요청을 보내고 실패합니다. 나는 다음과 같은 rootUri
를 사용하는 경우
, 모의 서버로 리디렉션하지 않고 서비스 요청이 실패 :
// Snippet from mockserver.js
var oMockServer = new MockServer({
rootUri: "/destinations/northwind/V2/Northwind/Northwind.svc/"
});
Failed to load https://services.odata.org/V2/Northwind/Northwind.svc/ $metadata?sap-language=DE: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' https://webidetesting9515320-s0015250556trial.dispatcher.hanatrial.ondemand.com ' is therefore not allowed access. The response had HTTP status code 501.
Another question on Stackoverflow는 "와일드 카드"루트 URI하지만,이를 사용하여 모의 서버를 보여줍니다 또한 실패 : 나는 모의 서버 구성 작업을 할 수
// Snippet from mockserver.js
var oMockServer = new MockServer({
rootUri: "/"
});
수있는 유일한 방법은 rootUri
으로 동일한 URL을 사용하는 것입니다 내가 DataSource에의 URI 내가 조롱 원하는대로 manifest.json을 작성 S :
// Snippet from mockserver.js
var oMockServer = new MockServer({
rootUri: "https://services.odata.org/V2/Northwind/Northwind.svc/"
});
위의 코드는 작동하지만, 웹 IDE이 나쁜 관행이라고 주장한다 :
error: Fiori Architectural Guidelines: ESLint(sap-no-hardcoded-url): Hardcoded (non relative) URL found. (img)
내 질문은 지금 : 모의 서버가 상대방 rootUri
과 함께 의도 된 방식으로 실행되도록하려면 어떻게해야합니까?
웹 애플리케이션/manifest.json을 (발췌)
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "sap.ui.tutorial.walkthrough",
"type": "application",
"i18n": "i18n/i18n.properties",
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"applicationVersion": {
"version": "1.0.0"
},
"dataSources": {
"invoiceRemote": {
"uri": "https://services.odata.org/V2/Northwind/Northwind.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
}
}
},
...
웹 애플리케이션/테스트/mockServer.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>Hello World App - Test Page</title>
<script src="/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_belize"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.tutorial.walkthrough": "../"
}'></script>
<script type="text/javascript">
sap.ui.getCore().attachInit(function() {
sap.ui.require([
"sap/ui/tutorial/walkthrough/localService/mockserver",
"sap/m/Shell",
"sap/ui/core/ComponentContainer"
], function(mockserver, Shell, ComponentContainer) {
mockserver.init();
new Shell({
app: new ComponentContainer({
name: "sap.ui.tutorial.walkthrough",
height: "100%"
})
}).placeAt("content")
});
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
웹 애플리케이션/LOCALSERVICE/mockserver.js
sap.ui.define([
"sap/ui/core/util/MockServer"
], function (MockServer) {
"use strict";
return {
init: function() {
// create
var oMockServer = new MockServer({
rootUri: "https://services.odata.org/V2/Northwind/Northwind.svc/"
});
var oUriParameters = jQuery.sap.getUriParameters();
// configure
MockServer.config({
autoRespond: true,
autoRespondAfter: oUriParameters.get("serverDelay") || 1000
});
// simulate
var sPath = jQuery.sap.getModulePath("sap.ui.tutorial.walkthrough.localService");
oMockServer.simulate(sPath + "/metadata.xml", sPath + "/mockdata");
// start
oMockServer.start();
}
};
});
웹 애플리케이션/LOCALSERVICE/metadata.xml
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="NorthwindModel" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="Invoice">
<Key>
<PropertyRef Name="ProductName"/>
<PropertyRef Name="Quantity"/>
<PropertyRef Name="ShipperName"/>
</Key>
<Property Name="ShipperName" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"
Unicode="true"/>
<Property Name="ProductName" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false"
Unicode="true"/>
<Property Name="Quantity" Type="Edm.Int16" Nullable="false"/>
<Property Name="ExtendedPrice" Type="Edm.Decimal" Precision="19" Scale="4"/>
</EntityType>
</Schema>
<Schema Namespace="ODataWebV2.Northwind.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="NorthwindEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="Invoices" EntityType="NorthwindModel.Invoice"/>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
자습서의 26 단계를 확인하십시오. 원격 OData 서비스에 대한 액세스와 관련하여 "참고"및 "주의"절이 있습니다. –
자습서의 "참고"및 "주의"상자는 브라우저에서 CORS 처리의 효과에 대해 설명합니다. 원격 데이터 대신 로컬을 사용한다는 목적으로 모의 서버를 만듭니다. CORS는 더 이상 문제가 아니며 "메모"및 "주의"상자는 관련이 없습니다. 내가 여기서 뭔가를 놓치고 있니? –
"Walkthrough - Step 27"에서 다운로드 한 것과 정확히 일치하는 파일로 시도하십시오. 그런 다음 다운로드 한 것과 똑같이 모의 모드로 실행해야합니다. –