swagger-ui: 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 Screen Shot 2013-02-11 at 10 54 09 PM

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
                }
            ]
        }
    ]
}
]
}

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 29 (11 by maintainers)

Most upvoted comments

Thanks, I enabled CORS and it works! 👍

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