cancel
Showing results for 
Search instead for 
Did you mean: 

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?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

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

Answers (1)

Answers (1)

anton_levin
Advisor
Advisor
0 Kudos

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/b068356dd7c34cf7ad6b6023dee...

[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

0 Kudos

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 Kudos

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