Koa-swagger:设置cors后访问控制来源错误
Koa-swagger: access-control-origin error after cors being set
我正在玩弄 koa 和 swagger。即使在我设置了 cors 之后,它也会给我 "may not have the appropriate access-control-origin settings" 的错误。
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"}]}
不幸的是,当出现 CORS 错误时,swagger ui 无法给出完整的警告。对于您的情况,请查看 http://localhost:8080/api-docs.json/root 是否存在。否则,您可能会收到相同的错误消息。
看起来 swagger 定义是 quite old (1.0)。你能看看使用更新的库吗,比如 https://github.com/swagger-api/swagger-node?
我正在玩弄 koa 和 swagger。即使在我设置了 cors 之后,它也会给我 "may not have the appropriate access-control-origin settings" 的错误。
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"}]}
不幸的是,当出现 CORS 错误时,swagger ui 无法给出完整的警告。对于您的情况,请查看 http://localhost:8080/api-docs.json/root 是否存在。否则,您可能会收到相同的错误消息。
看起来 swagger 定义是 quite old (1.0)。你能看看使用更新的库吗,比如 https://github.com/swagger-api/swagger-node?