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.

Advertisements

Searching a Cloudant DB search index with Node-Red

After much searching the internet and seeing multiple posts about this subject I can only think that many others are greatly confused with the use of the Cloudant In node in Node-Red. I think my problem was terminology and not being familiar enough with the Cloudant nomenclature more than anything and the user interface in Node needs a little more work.

I basically want to return all documents where name=XXXXX. My document is pretty simple, here is an example:

review-doc

So lets start by looking at my index definition:

cloudant_index

Now you will notice I have three references to “namesearch”:

  1. The design document name is “_design/namesearch”
  2. The Index name is “nameSearch”
  3. The index in the search index function is also named “nameSearch”

My flow takes in an HTTP request, formats it with the Selector node, and passes the query on to the Cloudant In node:

flow

The selector node is pretty basic, after following many different instructions I finally resolved the problems with this function:

selector

This results in a payload that looks like this:

nameSearch:Create a category layout

The Cloudant In node now has the following configuration (which seemed to be the primary problem, I will explain later:

cloudantin

The problem I had was I could not future out the search index fields. Mainly because this is the form when no fields are filled in:

designdoc

Notice it specifically says “design document“. Now, anyone that is not familiar with this, based on my configuration, would most likely fill it out like this:

node-red cloudant in

But after scouring many documents on the internet a suggestion was to just remove the “_design/” from the first field. Which resulted in the correct version I have above:

cloudantin

Needless to say this actually took me hours to figure out because I thought it was something with the query being passed in!

If you are not familiar with Node-Red then click this link.

Node-RED boilerplate on #BlueMix now uses Cloudant NoSQL DB

Not sure if anyone noticed this but the Node-RED boilerplate application on BlueMix now uses the Cloudant NoSQL database service for storage. The beta version used Mongo:

CLOUDANT