There doesn't seem to be a lot of answers (but lots of questions) out there on how to handle this, so I'm going to add my name to the chorus and pray for an answer that doesn't involve Node.
My error via Chrome console:
1. POST https://gateway.watsonplatform.net/visual-recognition-beta/api
2. XMLHttpRequest cannot load https://gateway.watsonplatform.net/visual-recognition-beta/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.
I'm using a Rails AJAX request as such:
$.ajax({
method: "POST",
version: 'v2-beta',
url: "https://gateway.watsonplatform.net/visual-recognition-beta/api",
password: "-----------",
username: "-----------",
version_date:'2015-12-02',
visual_recognition: [
{
name: "visual-recognition-service",
label: "visual_recognition",
plan: "free",
credentials: {
url: "https://gateway.watsonplatform.net/visual-recognition-beta/api",
password: "----------",
username: "---------"
}
}
],
image: "/images/image1.jpg",
contentType: 'application/json'
}).done(function(msg){
if (200) {
console.log("This is a test for if.")
} else {
console.log("This is a test for else.")
}
});
For this particular prototype app, I have Rack::Cors set up to let anything work. This is in my application.rb:
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :patch, :options, :head],
:expose => ['access-token', 'expiry', 'token-type', 'uid', 'client', 'auth-token'],
:max_age => 0
end
end
Is there anyone out there that knows how these things are to be configured to get around this? I have to assume there's a way to access these APIs without having to fire up a Node instance.