无法在UI中读取swagger的文档(Rails项目,本地主机)

问题描述 投票:0回答:1

[当我进入http://localhost:3000/api/swagger时,我在文档的地址字段http://api.webcrm.dev:3000/doc中看到了,结果是消息Can't read from server. It may not have the appropriate access-control-origin settings.,而不是我的api的端点等。

我试图找到适当的地址以在本地主机中使用它。

控制台

Settings.api
=> {"url_options"=>{"host"=>"api.webcrm.dev", "port"=>3000, "version"=>"/v1/"},
 "swagger"=>{"discovery_url"=>{"host"=>"api.webcrm.dev", "port"=>3000, "path"=>"/doc"}}}

application.yml

api:
  url_options:
    host: api.webcrm.dev
    port: 3000
    version: /v1/
  swagger:
    discovery_url:
      host: api.webcrm.dev
      port: 3000
      path: /doc

config / initializers.010_swagger.rb

GrapeSwaggerRails.options.url     = Settings.api.swagger.discovery_url.path
GrapeSwaggerRails.options.app_url = "http://#{Settings.api.swagger.discovery_url.host}#{ ':' + Settings.api.swagger.discovery_url.port.to_s if Settings.api.swagger.discovery_url.port.present? }"

routes.rb

mount API => '/api' if ENV['ASSETS_PRECOMPILE'].blank?
  mount GrapeSwaggerRails::Engine => '/api/swagger'
  get '/api', to: redirect('/api/swagger')

但是在日志输出中,我看到:

2020-02-19 12:11:07 +0700: HTTP parse error, malformed request (): #<Puma::HttpParserError: Invalid HTTP format, parsing fails.>
2020-02-19 12:11:07 +0700: ENV: {"rack.version"=>[1, 3], "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "SCRIPT_NAME"=>"", "QUERY_STRING"=>"", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"puma 3.7.0 Snowy Sagebrush", "GATEWAY_INTERFACE"=>"CGI/1.2"}
---

我如何找到合适的文档地址,为什么它不会自动输入?非常感谢您的帮助!

P.S .: Rails 4.2.11.1 ruby 2.3.8p459

ruby-on-rails ruby swagger swagger-ui
1个回答
0
投票

找到正确的地址:http://localhost:3000/api/swagger_doc看起来我们应该使用configs做一些事情

© www.soinside.com 2019 - 2024. All rights reserved.