Can't read from server. It may not have the appropriate access-control-origin settings. ?
Hi,
The server returns the following message: "Can't read from server. It may not have the appropriate access-control-origin settings."
The API URL is: http://swagger-espn.mobovivo.com/api-docs.json
Could you please help to fix the issue?
Thanks in advance

SPEC FILE
{
"basePath": "http://espn-server.herokuapp.com/api",
"swaggerVersion": "0.1a",
"apiVersion": "1.0",
"apis": [
{
"path": "/info.json",
"format": "json",
"description": "Get API info and current match",
"operations": [
{
"httpMethod": "GET",
"summary": "Get API info and current match",
"nickname": "info",
"tags": [
"production"
],
"deprecated": false
}
]
},
{
"path": "/info/{id}.json",
"format": "json",
"description": "Get API info and current event",
"operations": [
{
"httpMethod": "GET",
"summary": "Show Event Info.",
"nickname": "showByIdOne",
"tags": [
"production"
],
"deprecated": false,
"parameters": [
{
"name": "id",
"description": "id = 1",
"dataType": "integer",
"allowMultiple": false,
"required": true,
"paramType": "path"
}
],
"errorResponses": [
{
"reason": "Not found",
"code": 404
},
{
"reason": "Invalid ID",
"code": 400
}
]
}
]
}
]
}
Your server is not allowing CORS requests:
curl -i "http://swagger-espn.mobovivo.com/api-docs.json"
HTTP/1.1 200 OK
Date: Tue, 12 Feb 2013 05:14:27 GMT
Server: Apache/2.2.20 (Ubuntu)
Last-Modified: Tue, 12 Feb 2013 04:02:39 GMT
ETag: "738ec-154-4d57f18baad57"
Accept-Ranges: bytes
Content-Length: 340
Content-Type: application/json
In order to run the swagger-ui from a host other than mobovivo.com, you'll have to return the proper header values for Access-Control-Allow-Methods and Access-Control-Allow-Origin, like such:
curl -i "http://api.wordnik.com/v4/resources.json"
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Origin, X-Atmosphere-tracking-id, X-Atmosphere-Framework, X-Cache-Date, Content-Type, X-Atmosphere-Transport, *
Access-Control-Allow-Methods: POST, GET, OPTIONS , PUT
Access-Control-Allow-Origin: *
Access-Control-Request-Headers: Origin, X-Atmosphere-tracking-id, X-Atmosphere-Framework, X-Cache-Date, Content-Type, X-Atmosphere-Transport, *
Content-Type: application/json
Date: Tue, 12 Feb 2013 05:14:27 GMT
Content-Length: 319
Connection: keep-alive
Thanks, I enabled CORS and it works! :+1:
great news
Could you please tell me how? I have a pretty standard webapp running on tomcat (6/7). I always get that message and I do not really understand what I have to do.
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Wed, 08 May 2013 16:20:52 GMT
{"apiVersion":"0.1-ALPHA","swaggerVersion":"1.0","basePath":"http://localhost:9999/","apis":[{"path":"/api-docs/rest/api/order"}]}
http://enable-cors.org/server.html or http://stackoverflow.com/questions/12048345/how-do-i-tell-tomcat-to-support-cors-for-static-content might help you.
Just got mine working... Awesome!
pls re-open this issue, I got mine working from localhost, but if I access it from another ip address it will return can't read from server....
localhost version
And this is my response header from localhost :
Access-Control-Allow-Headers:Content-Type, api_key, Authorization, x-requested-with, Total-Count, Total-Pages, Error-Message Access-Control-Allow-Methods:POST, GET, DELETE, PUT, OPTIONS Access-Control-Allow-Origin:* Access-Control-Max-Age:1800
Am I missing something ?
Thanks in advance
@toshim45 - what's the output you're getting when running:
curl -i "http://localhost:8080/pena-im/api-docs"
hi @webron
$ curl -i "http://localhost:8080/pena-im/api-docs"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, DELETE, PUT, OPTIONS
Access-Control-Allow-Headers: Content-Type, api_key, Authorization, x-requested-with, Total-Count, Total-Pages, Error-Message
Access-Control-Max-Age: 1800
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 19 Aug 2014 19:47:47 GMT
{"apiVersion":"1.0","swaggerVersion":"1.2","apis":[{"path":"/default/compose-controller","description":"Compose Controller"},{"path":"/default/home-controller","description":"Home Controller"},{"path":"/default/inbox-controller","description":"Inbox Controller"}],"info":{"title":"default Title","description":"Api Description","termsOfServiceUrl":"Api terms of service","contact":"Contact Email","license":"Licence Type","licenseUrl":"License URL"}}
sorry my mistake, my configuration is wrong in index.html :) it should be ip address, not localhost. thanks @webron
You rock man!
Hi Guyz, I just started using swagger, can you help me understand how do I use it to document my REST API's? Thanks in advance!!
I got it downloaded from github , but now how to initiate to make it work for my own API's instead of petstore already existing one
@jhambj - Please send a post to https://groups.google.com/forum/#!forum/swagger-swaggersocket with the details of your application, and I'll help you from there.
just doing that but even I am not sure what all details are needed though leaving a post there.Thank you so much.
Hi, I could solve this issue on Tomcat server, but it remains a problem on websphere application server profile as a server. Do you have any way to fix this?
Many thx :-)
Not sure why websphere would be any different. Enabling CORS is normally done at the application level, though tomcat has its own filter you may have used. Just enable it on websphere and you should be done.
http://stackoverflow.com/questions/24277953/how-to-define-cors-in-websphere-application-server-liberty-profile-v8-5 That helps.
Why we need to accept CORS for fetching json file? you don't need it for AJAX GET
You don't need CORS for a GET. Swagger-js (the underlying library for the UI) does not differentiate in the request process and therefore sends a preflight request.