How to get rid of "500 Internal Server Error" using ui5-middleware-simpleproxy

4.2k views Asked by At

I built an SAPUI5 app using UI5 Tooling and now I'm having trouble connecting it to an OData service.
500 Internal Server Error


Since the real url to the OData Service is not public, let's just call it:

http://app99.sap.domain.com/sap/opu/odata/sap/Z_DOMAIN_SRV/

and opening it in my browser, adding $metadata?sap-language=DE at the end, works - I get the XML metadata document.


These are the files I tried to change to connect to the OData service:

  • webapp
    • manifest.json
  • package.json
  • ui5.yaml

Adding a "dataSources"-object and a "models"-object in manifest.json

{
  "sap.app": {
    ...
    "dataSources": {
      "oDataService": {
        "uri": "/sap/opu/odata/sap/Z_DOMAIN_SRV/",
        "type": "OData"
      }
    }
  },
  "sap.ui5": {
    ...
    "models": {
      ...
      "": {
        "dataSource": "oDataService",
        "preload": true,
        "settings": {
          "useBatch": false
        }
      }
    },
    ...
  }
}

I also tried changing the "uri" value to the real link, http://app99.sap.domain.com/sap/opu/odata/sap/Z_DOMAIN_SRV/, but then I expectedly get a Cross-Origin error:
Cross-Origin Error

So I tried setting up a proxy by adding this to my package.json:

{
  ...
  "devDependencies": {
    "ui5-middleware-simpleproxy": "^0.5.1"
  },
  "ui5": {
    "dependencies": [
      "ui5-middleware-simpleproxy"
    ]
  },
  ...
}

and adding this to my ui5.yaml file:

...
server:
  customMiddleware:
    - name: ui5-middleware-simpleproxy
      mountPath: /sap/opu/odata/sap/Z_DOMAIN_SRV
      afterMiddleware: compression
      configuration:
        baseUri: "http://app99.sap.domain.com/sap/opu/odata/sap/Z_DOMAIN_SRV/"

hoping that now
http://localhost:8080/sap/opu/odata/sap/Z_DOMAIN_SRV/$metadata?sap-language=DE
would turn into
http://app99.sap.domain.com/sap/opu/odata/sap/Z_DOMAIN_SRV/$metadata?sap-language=DE
and it would work, but that isn't the case - I just get the error from the screenshot on top.

Any idea what I am missing?
I really want to make it work with this ui5-middleware-simpleproxy, because I don't want to start up two servers manually (the UI5 Tooling one and another one for the proxy). Currently I just need to do ui5 serve and everything works out of the box.

1

There are 1 answers

0
Cold_Class On BEST ANSWER

After changing the config in ui5.yaml it worked.
I don't quite understand how the relationship between mountPath and baseUri works and why it worked this way, but some problems can be solved with try and error like in my case :D

...
server:
  customMiddleware:
    - name: ui5-middleware-simpleproxy
      mountPath: /sap/opu/odata/sap
      afterMiddleware: compression
      configuration:
        baseUri: "http://app99.sap.domain.com/sap/opu/odata/sap"