我正在玩koa和swagger。即使在我设置了cors之后,它也会给出“可能没有适当的访问控制 - 原点设置”的错误。
App.js
var cors = require('koa-cors');
var swaggerApp = koa(),
port = 8080;
var options = {
origin: '*',
headers: ['Content-Type', 'Authorization','Origin', 'X-Requested-With']
}
curl i http://localhost:8080/api-docs.json
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,HEAD,PUT,POST,DELETE
Access-Control-Allow-Headers: Content-Type,Authorization,Origin,X-Requested-With
Content-Type: application/json; charset=utf-8
Content-Length: 203
Date: Mon, 31 Aug 2015 17:13:55 GMT
Connection: keep-alive
{"basePath":"http://localhost:8080","apiVersion":"1.0","swaggerVersion":"1.0","swaggerURL":"/swagger","swaggerJSON":"/api-docs.json","apis":[{"path":"/api-docs.json/root","description":"All about API"}]}
答案 0 :(得分:0)
不幸的是,当出现CORS错误时,swagger ui无法提供完整的警告。在您的情况下,请查看http://localhost:8080/api-docs.json/root是否存在。如果没有,您可能会收到相同的错误消息。
看起来看起来很昂贵(1.0)。您能否看一下使用较新的库,例如https://github.com/swagger-api/swagger-node?