webview - access-control-allow-origin 不允许来源(使用 cordova 将 angular 转换为移动设备)

webview - origin is not allowed by access-control-allow-origin (convert angular to mobile using cordova)

我正在尝试使用 Alfresco adf 组件 (https://github.com/Alfresco/alfresco-ng2-components) 创建一个 angular 应用程序并且还需要一个移动应用程序,所以我决定使用 cordova 生成 apk。

我按照以下教程 (https://medium.com/@nacojohn/convert-your-angular-project-to-mobile-app-using-cordova-f0384a7711a6) 生成我的 apk。

一切似乎都正常,apk 已生成并安装在 BlueStack 中,直到我必须在我的应用程序中登录。

Origin is not allowed by access-control-allow-origin

我知道我需要一个白名单策略来导航应用程序 webview

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>HelloWorld</name>
  <description>
    A sample Apache Cordova application that responds to the deviceready event.
  </description>
  <author email="dev@cordova.apache.org" href="http://cordova.io">
    Apache Cordova Team
  </author>
  <content src="index.html" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <allow-navigation href="*" />
  <platform name="android">
    <allow-intent href="market:*" />
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
  </platform>
  <plugin name="cordova-plugin-device" spec="^2.0.2" />
  <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
  <engine name="android" spec="^7.0.0" />
  <engine name="ios" spec="^4.5.4" />
</widget>

index.html

 <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"

我的 angular 网络应用程序有一个开发服务器代理来修复 CORS 问题

proxy.conf.json

{
  "/alfresco": {
    "target": "server-url",
    "secure": false,
    "changeOrigin": true
  },
  "/activiti-app": {
    "target": "another-server-url",
    "secure": false,
    "changeOrigin": true
  }
}

我不知道我还需要做什么。我做错了什么吗?需要做更多事情吗?

谢谢

我认为您应该在 Alfresco 服务器中启用 CORS,您可以通过以下任一方式实现:

  • 在您的 Alfresco 扩展中包含此 dependency
  • 或者直接在 Tomcat 服务器中启用 CORS,可以在 Tomcat documentation.
  • 中找到完整的详细信息

您必须启用 CORS 以了解详细信息,请参阅 Getting Started with Alfresco Application Development Framework

我的问题是 app.config.json 中缺少配置。

而不是

"ecmHost": "http://{hostname}{:port}",
"bpmHost": "http://{hostname}{:port}"

我只需要为我的服务器设置 ecmHost 和 bpmHost,一切正常。

感谢大家的帮助