Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Resource with two parameters give "Access-Control-Allow-Origin" error #14

Closed
nebril opened this issue Jul 6, 2012 · 2 comments
Closed

Comments

@nebril
Copy link

nebril commented Jul 6, 2012

I am not sure if this is issue with this module or the ui, but I am posting it here. I have three actions for one resource and I have a problem with one of them. Two others work without any problem, but this one keeps giving me following error:
XMLHttpRequest cannot load http://localhost:8002/topic/findAll/1/2. Origin http://localhost is not allowed by Access-Control-Allow-Origin."

this is my resource:

exports.findAll = {
'spec': {
"path" : "/topic/findAll/{offset}{limit}",
"notes" : "Offset and limit",
"summary" : "Get topics list from given integer offset and limited by given integer limit",
"params" : new Array(
  swagger.pathParam("offset", "Offset", "string"),
  swagger.pathParam("limit", "Limit", "string")
),
"outputModel" : {
  "name" : "List[topic]",
  "responseClass" : watsonModels.topic
},
"errorResponses" : new Array(
  swagger.error(400, "Invalid limit or offset value"),
  swagger.error(404, "Topic not found")
),
"nickname" : "findAll"
},

'action': function (req,res) {
console.log('get list');
var offset = parseInt(url.parse(req.url,true).query["offset"]);

if (!offset) {
  throw swagger.error(400, "invalid offset supplied"); }

var limit = parseInt(url.parse(req.url,true).query["limit"]);

if (!limit) {
  throw swagger.error(400, "invalid limit supplied"); }

var output = new Array();
for (var i = 0; i < swagger.Randomizer.intBetween(1,limit); i++) {
  output.push(swagger.containerByModel(watsonModels.topic, {}, -1));
}

res.send(JSON.stringify(output));
}
};

when I get rid of the limit param from path and params subarray, the request starts working.

Do you have any idea how can I work this around or where to look in js to make a fix?

Cheers,
Maciej

@fehguy
Copy link
Contributor

fehguy commented Aug 27, 2012

Can you use chrome dev tools and post the URL that is being called?

@fehguy
Copy link
Contributor

fehguy commented Oct 31, 2012

Added convenience setHeaders method in swagger.js.

@fehguy fehguy closed this as completed Oct 31, 2012
theganyo pushed a commit that referenced this issue Jul 27, 2015
add overwrite this and following
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants