Replies: 1 comment 1 reply
-
The easiest way to do this would be to have require "roda"
class App < Roda
plugin :halt
plugin :multi_run
route do |r|
r.root { 'Main' }
r.get('err201') { r.halt 201 }
r.multi_run
end
end
module MyExtension
class Routes < App
route do |r|
r.root { 'My Extension' }
r.get('err202') { r.halt 202 }
end
end
end
App.run "my_extension", MyExtension::Routes
run App.freeze.app |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm putting together a simple bot framework with Roda at its core. The framework features extensions which may contain Roda routes, which is why I'm managing these extra routes with
multi_run
so far. Here's a simple example:And here's what it serves:
curl -i http://127.0.0.1:9292/
-> Main ✅curl -i http://127.0.0.1:9292/err201
-> HTTP/1.1 201 Created ✅curl -i http://127.0.0.1:9292/my_extension/
-> My Extension ✅curl -i http://127.0.0.1:9292/my_extension/err202
-> HTTP/1.1 500 Internal Server Error ⛔️The reason is quite obvious: My extension is a separate Roda app which doesn't load the halt plugin. To make it work, all it takes is
plugin :halt
in MyExtension::Routes.However, I'd like some plugins (the ones used in App) to be loaded in all extensions already without the need to explicitly do so. I guess that's a no go with
multi_run
.Is there a recommended way to achieve this while still having the extension routes nicely tucked away in a module or class each?
Beta Was this translation helpful? Give feedback.
All reactions