Rails Grape-Swagger: get current domain for base_path
api, ruby
Solution
OK, for anyone wandering here after all these years (like I did), - this is the solution that worked for me:
add_swagger_documentation base_path: lambda { |request| "http://#{request.host}:#{request.port}" }
... #other options
Basically you just have to pass a proc that yields `Grape::Request` instance, from which you can pull the host and port data.
Problem
I've got the following Grape root class definition ``` module Api class Root < Grape::API mount Api::Version1 add_swagger_documentation :mount_path => 'docs', :base_path => "/api", :markdown => true, :hide_documentation_path => true end end ``` The problem is that ":base_path" should include a full URL, and I don't know where to get it. I've checked ENV variable, and there is nothing close to the current domain. There is also no "request" object of any kind. Is there any way in Ruby I can just get the current domain, ie HTTP_HOST variable?