Allowing CORS from a Node-Red Bluemix application

I wrote a rating application some time ago in Node-Red and have since needed another similar application but with slightly different behavior. So I went ahead and created a new Node-Red application on Bluemix and decided to start from scratch since it was so simple to set up. This application has three requests – Get Rating, Post Rating, and Post Comment. Here is the current flow:

Image (1) rate-flow-680x422.png for post 5391

The problem I had was the requests actually respond with JSON and I could not figure out how to enable CORS!

The first thing I did was in the Image (2) cors.png for post 5391 node I added the following to the response:

Image (3) cors2.png for post 5391

And that did not work. Then, I stumbled upon this in my Cloudant dashboard in the Account Section under CORS:

 

Image (4) cloudant_admin-680x212.png for post 5391

Once I checked all domains it worked fine! I am sure I can restrict the domains appropriately but I guess I don’t understand why the CORS options are under the Cloudant section and not the base application somewhere. I would think this is a specific thing to hitting the Cloudant service directly, not through a Node-Red Node. I am very interested in hearing others opinions on this.

Update:

After using the Cloudant UI to update my profile I went back and checked the bluemix-settings.js saw it indeed added the httpNodeCors line to the profile:

httpNodeCors: { origin: “*”, methods: [‘GET’,’PUT’,’POST’,’DELETE’] },

So this is clearly the issue as I saw a similar question on developerworks but saw no example of the syntax.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s