Skip to Content
0

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

Sep 07, 2017 at 08:53 PM

149

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

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

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

Share
10 |10000 characters needed characters left characters exceeded
Anton Levin
Sep 08, 2017 at 04:46 AM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Can you please provide the other posts that show how to get around CORS from an IoTMMS perspective? I did not see any when I searched.

0
0
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.

0