4

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?

2 Answers 2

6

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.

0
0

I've had decent luck using http://localhost:9292/api. I think another alternative would be to keep these settings in a config yml file, and you could possibly set that based on RACK_ENV's value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.