Skip to Content
avatar image
Former Member

How do I enable CORS so I can consume data from the ODATA API that the IoT MMS Service produces?

Hey folks,

Just leveraging a lightweight HTML5 (bootstrap + JQuery) page that will show output data from an arduino device I hooked up.

The page itself will be hosted on cloud platform, but an issue I'm running into right now while previewing the page on my desktop and from the WebIDE is that CORS is not enabled specifically I'm getting the error "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.".

How do I get around this?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 08, 2017 at 09:03 PM

    I figured it out, and I won't let this be one of those phantom posts online where OP doesn't post his resolution.

    To get around CORS, one must first leverage destinations in cloud platform. The github has some destinations you can upload and the steps for configuring it are here.

    Now, to leverage the destination in this case you have to create a file called neo-app.json in the root of your project, at which point you can populate it with the destinations you have just created

    {
      "routes": [
        {
          "path": "/iotmms",
          "target": {
            "type": "destination",
            "name": "iotmms"
          },
          "description": "MMS Destination"
        },
        {
          "path": "/iotrdms",
          "target": {
            "type": "destination",
            "name": "iotrdms"
          },
          "description": "RDMS Destination"
        }
      ]
    }
    

    and then to leverage that from within javascript you can simply just refer to the url

    var url = "/iotmms/v1/api/http/app.svc/[odataquery]";

    That's it!

    Cheers,
    Jath

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 08, 2017 at 04:46 AM

    Hello Jathavan,

    you would need to leverage HTTP Destinations [1]. Please, refer to the IoT StarterKit UI5 consumption examples [2] or [3], if you would like to see it working end-to-end.

    Regards,

    Anton

    P.S. Please, also familiarize yourself with the Community Rules of Engagements [4] and especially with #3 - search before you post. CORS question was asked multiple times already in different contexts.

    [1] https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/b068356dd7c34cf7ad6b6023deeb317d.html

    [2] https://github.com/SAP/iot-starterkit/tree/master/neo/apps/ui5/consumption

    [3] https://github.com/SAP/iot-starterkit/tree/master/neo/apps/ui5/consumption-advanced

    [4] https://www.sap.com/community/about/rules-of-engagement.html

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Anton Levin

      Unfortunately none of those provided answers to my problem. I'm not leveraging SAPUI5, I'm using regular HTML5 capabilities with JQuery and Bootstrap.