ruby-on-rails – 使用Swagger和Foreman Rails服务器获取“Acces
发布时间:2020-12-17 02:22:34 所属栏目:百科 来源:网络整理
导读:我的服务器当前运行在0.0.0.0:5100.当我尝试访问我的Swagger文档时,我在控制台中收到以下错误: XMLHttpRequest cannot load http://0.0.0.0/api/v1/types.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'ht
我的服务器当前运行在0.0.0.0:5100.当我尝试访问我的Swagger文档时,我在控制台中收到以下错误:
XMLHttpRequest cannot load http://0.0.0.0/api/v1/types.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:5100' is therefore not allowed access. 我想知道为什么会这样.这是我在index.html中的Swagger配置: $(function () { window.swaggerUi = new SwaggerUi({ url: "/api-docs.json",dom_id: "swagger-ui-container",supportedSubmitMethods: ['get','post','put','delete'],onComplete: function(swaggerApi,swaggerUi){ log("Loaded SwaggerUI"); if(typeof initOAuth == "function") { /* initOAuth({ clientId: "your-client-id",realm: "your-realms",appName: "your-app-name" }); */ } $('pre code').each(function(i,e) { hljs.highlightBlock(e) }); },onFailure: function(data) { log("Unable to Load SwaggerUI"); },docExpansion: "none" }); 解决方法
您是否为您的网络服务启用了
CORS支持?
The Swagger documentation号召该工作需要CORS支持.在我添加CORS支持之前,您收到的错误消息与我在Grails项目中获得的消息完全相同.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |