padrino / padrino-framework

Padrino is a full-stack ruby framework built upon Sinatra.
http://www.padrinorb.com
MIT License
3.37k stars 508 forks source link

Handling nested Grape mounts? #2156

Open fatmcgav opened 6 years ago

fatmcgav commented 6 years ago

I'm trying to use Grape for providing 'versioned' APIs with Padrino.

I'd like to just mount a single API class in Padrino, e.g.: Padrino.mount('API', :app_file => Padrino.root('api/base.rb'), :app_class => 'API::Base').to('/api') Which then mounts the version APIs.

However whenever I try this I get an 'Unitialized Constant' error. Further details can be found here: https://groups.google.com/forum/?nomobile=true#!topic/padrino/9aA5wFpWp4k and here: https://github.com/fatmcgav/padrino-grape-example/commit/0e3a6c6d43a9b697822ec8e1988378979c562eb1

adam12 commented 6 years ago

The Unitialized Constant error comes from the v1.rb file not being required.

So the easy fix for that is obviously:

diff --git a/api/base.rb b/api/base.rb
index dd5fd3a..9519b43 100644
--- a/api/base.rb
+++ b/api/base.rb
@@ -1,3 +1,5 @@
+require_relative "v1"
+
 module Aurora
   module API
     class Base < Grape::API

It might break the reloader, but I am not sure if the reloader will even work for Grape applications.

fatmcgav commented 6 years ago

@adam12 Ah, that was a relatively easy fix...

Though I'm now seeing routes listed twice...

adam12 commented 6 years ago

I'm not sure how much help I'll be there sadly.

wikimatze commented 6 years ago

Hi @farcaller, I've setup an example app under https://github.com/wikimatze/padrino-nested-grape-mounts which do the nesting in a way I understand modules in grape as explained under https://github.com/ruby-grape/grape#modules - just follow the README in https://github.com/wikimatze/padrino-nested-grape-mounts/blob/master/README.md to see what I did.