-
-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register Lotus applications #30
Comments
@jodosha this seems like it should be an issue on https://github.com/lotus/router instead? |
@lengarvey Lotus::Router is agnostic about Lotus applications and I'd like to keep it as it is. Probably it would require some new mechanism in Lotus::Router as base for this feature. |
I'm giving attention for this @jodosha. Maybe on Monday I send some code draft. |
@lucasas 👍 |
@jodosha where the application is creating this anonymous router? And where double routing dispatch is being made? Thanks dude |
@lucasas The "anonymous router" is something like this: # config.ru
# this router instance is anonymous
run Lotus::Router.new {
mount Backend::Application, at: '/backend'
mount Frontend::Application, at: '/'
} It's the only way that we have now for dispatch HTTP requests for multiple applications. |
Hey @jodosha, I've implemented a draft to accomplish flatten routes, registering a lot of applications. Some changes were made on But basically, now you can do the follow: Lotus::Routes.new(mount_at: 'backend') do
get '/flowers', to: 'flowers#index'
end This is completelly equal with the code below: Lotus::Routes.new do
namespace 'backend' do
get '/flowers', to: 'flowers#index'
end
end Another change on @router.each do |route|
puts route # => it will print #to_str from Lotus::Routing::Route
end
module Backend
class Application < Lotus::Application
configure do
root File.dirname(__FILE__)
load_paths << [
'controllers',
'views'
]
layout :backend
# defining mount point of this application
mount_at 'backend'
routes do
get '/login', to: 'sessions#new', as: :login
end
end
end
end The most important change ocurred here: lucasas@2b18990 The new class called run Lotus::Routing::Builder.new {
mount Backend::Application
mount Frontend::Application
} As each application defines its own Next steps:
I'm really want to know your opinion, realize if we are in the same page. Thanks. |
Hey @jodosha. Thoughts here? |
There is a little bug here to be resolved (thanks @arthurgeek) As my I've copied all routes from all applications to a single router, this router just call the recognized destination without pass through I'm visualizing all possibilities before go ahead. If you guys, specially @jodosha, have some idea to help me, would be great. One of them is: I could instantiate a new |
@lucasas Yes, I know, what you mean. Sorry for not making clear that this was the challenge of this feature, and instead you had to figure out it by yourself. I opened this ticket to brainstorm with you guys. As we haven't already defined a stable architecture, my proposal is to hold on this, as it feels like premature optimization. We don't want to bend the framework too early. |
Yes, this is really a challenge. I spent today 6 hours trying to figure out how to solve this, and I was intending to work on it in the next days. As you said, I might give up to do it for a while. But I think that step 1 (Pass to the single applications the :at prefix, so they are aware of the prefix configuration) should be done right now. What is your opinion? |
As I talked with @jodosha, for while, I'll keep focus on the first feature (Pass to the single applications the :at prefix, so they are aware of the prefix configuration). Actually, this is done, I'm gonna extract it, create some documentation and tests, before open a PR. |
Hey @jodosha, in my solution, the first step is coupled to second one, in a way that one doesn't work without the other. I want to explain what I've done to resolve just the first step. I've changed module Backend
class Application < Lotus::Application
configure do
router_namespace 'backend'
routes do
get '/login', to: 'sessions#new', as: :login
end
end
end
end
module Frontend
class Application < Lotus::Application
configure do
router_namespace 'frontend'
routes do
get '/login', to: 'sessions#new', as: :login
end
end
end
end Into application.routes = Lotus::Router.new(
resolver: resolver,
default_app: default_app,
scheme: configuration.scheme,
host: configuration.host,
port: configuration.port
)
application.routes.namespace(configuration.router_namespace, &configuration.routes) It's simple, all routes are defined respecting a In my module Lotus
module Routing
class Builder
def initialize(&blk)
@router = Lotus::Router.new
instance_eval &blk
end
def mount(app)
@app = app.new
@router.mount @app, at: "/"
end
def call(env)
@router.call(env)
end
end
end
end
# config.ru
run Lotus::Routing::Builder.new {
mount Frontend::Application
mount Backend::Application
} As you can see, all application are mounted at the same point ( I'm still trying to figure out which approach can solve this problem, I mean, which alternative I have to do achieve first step solution. |
The microservices architecture uses an anonymous
Lotus::Router
instance. Mounted applications aren't aware of the prefix that we assign inconfig.ru
, this leads to wrong URL generation.Example:
This double routing dispatch is inefficient: a request goes thru two instances of
Router
, one fromconfig.ru
, one from the application.We can do introduce a new object like this:
It should:
:at
prefix, so they are aware of the prefix configuration.Imagine the following scenario, where we have two applications with the following routes and controllers:
With anoymous
Lotus::Router
:With registered applications (flatten routes)
The text was updated successfully, but these errors were encountered: