Cloud foundry 如何轻松地从html5应用程序中使用具有目标的nodejs后端?

Cloud foundry 如何轻松地从html5应用程序中使用具有目标的nodejs后端?,cloud-foundry,sap-web-ide,multitargeting,sap-cloud-platform,Cloud Foundry,Sap Web Ide,Multitargeting,Sap Cloud Platform,我想将html5模块与nodejs后端“连接”,以便前端可以访问后端以获取db逻辑。我发现,我必须在scp中创建一个目的地,并将其写入批准者的mta.yaml和xs-app.js文件中。不幸的是,它不能正常工作,因为有一个错误:“找不到” html5前端只发出一个ajax请求。 nodjs后端通过express接收请求,并使用db进行操作 我在scp中创建了一个名为backendApi的目标。url是节点\后端的url之一 mta.yaml文件中的代码片段: name: node_backend

我想将html5模块与nodejs后端“连接”,以便前端可以访问后端以获取db逻辑。我发现,我必须在scp中创建一个目的地,并将其写入批准者的mta.yaml和xs-app.js文件中。不幸的是,它不能正常工作,因为有一个错误:“找不到”

html5前端只发出一个ajax请求。 nodjs后端通过express接收请求,并使用db进行操作

我在scp中创建了一个名为backendApi的目标。url是节点\后端的url之一

mta.yaml文件中的代码片段:

name: node_backend
    type: nodejs
    path: node_backend
    requires:
      - name: mongodb-nemo-t01-service
      - name: cf_elb_postgres
    provides:
      - name: node_backend_api
        properties:
          url: '${default-url}'

- name: cfElbTimeline
    type: html5
    path: cfElbTimeline
    parameters:
      disk-quota: 500M
      memory: 500M
    build-parameters:
      builder: grunt
    requires:
      - name: node_backend_api
        group: destinations
        properties:
          name: backendApi
          url: '~{url}'
          forwardAuthToken: true
我的xs-app.js文件:

{
    "welcomeFile": "/index.html",
    "authenticationMethod": "route",
    "logout": {
        "logoutEndpoint": "/do/logout"
    },
    "routes": [{
        "source": "^(.*)$",
        "target": "$1",
        "service": "html5-apps-repo-rt",
        "authenticationType": "xsuaa"
    }, {
        "source": "^(.*)$",
        "target": "$1",
        "destination": "backendApi",
        "httpMethods": ["GET", "POST"],
        "authenticationType": "none"
    }]
}
通过前端访问后端已经工作过一次,但html5应用程序存储库存在问题,因此视图不可见。因此,我更改了它,但无法回到我可以通过approuterurl访问后端的那一点。也许这条路线的正则表达式有问题


任何人都可以检查我的代码或解释它应该如何工作吗?

在xs-app.json中定义的路由在与同一模式匹配时按条目顺序考虑。也就是说,您认为可能向API发出的任何请求都由第一个路由提供:即;HTML5 repo服务,仅包含静态文件

另外,区分路线也是一个好主意,以避免混淆。您可以通过添加路由前缀或使用不同的模式来区分API路由

例如:

{
    "welcomeFile": "/index.html",
    "authenticationMethod": "route",
    "logout": {
        "logoutEndpoint": "/do/logout"
    },
    "routes": [{
        "source": "^(.*)$",
        "target": "$1",
        "service": "html5-apps-repo-rt",
        "authenticationType": "xsuaa"
    }, {
        "source": "^/api/(.*)$",
        "target": "$1",
        "destination": "backendApi",
        "httpMethods": ["GET", "POST"],
        "authenticationType": "none"
    }]
}
然后,您可以从批准者处访问目的地,如下所示:

https://<approuter_url>/<app_name-version>/api/whatever.xsodata
https:////api/whatever.xsodata