-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Dynamic binding/rebinding of controllers after app start #433
Comments
Hey guys! I'll working on this issue. As soon as possible I will send my suggestion on a PR. Let me know if you have any advise for me about it :-) |
@lindoelio, are you still interested in submitting a PR? |
@bajtos , what is the use case for hot-reloading? I'm thinking users would add controller during development time, so it's not so critical to have the hot reloading feature. Discussed with @virkt25, this is a nice-to-have feature, but we can leave it post-GA given there are higher priority items for GA. |
I am fine with removing this item from 4.0 GA scope.
For example, IBM AppConnect uses LoopBack to define models & REST APIs on the fly. Their LoopBack server provides REST APIs to define (create) and remove connections to 3rd-party databases/services. When a new 3rd party database/service is connected, AppConnect need to create a set of models & controllers allowing its clients to access the new database/service through the LoopBack runtime. |
Hi, I'll working on this issue. I tried load controller after the app started and used Controller was added to app registry, but routes of controller were not created. Change in
to
and add:
After adding this code routes of controller were created. I tried add this code to Application.controller function ( The issue 433 was opened one year ago, and currently outdated, bacause For resolve this issue looks like we have to do some changes:
And for dynamic binding/rebinding of controllers after app start we can use
or
|
@raymondfeng Your solution is not helpful to add routes of the controller. Please see solution in my previous comment #433 (comment) |
In your case, the current implementation has the following class hierarchy: RestServer --> HttpHandler --> RoutingTable --> TrieRouter The RestServer discovers all controllers from the context and calls HttpHandler To fully allow the dynamic registration of controllers, we need to make sure one of the following happens:
|
You are want after add controller reset HttpHandler and rebuilds it with the latest list of controllers. Are you think is a good flow if I want to add dynamically 50 controllers? After each addition of a new controller we have to reset HttpHandler or we can add/delete routes and openapi definitions? |
I checkout your pull request #2122 and updated RestServer to subscribes to context events for controller bindings. After start application RestServer listening on 'bind' event of all loading controllers. I found out solution how to redefine routes in express js. Possible solution: we have to refactor RestServer._setupHandlerIfNeeded function to cleanup and recreate loopback-next configuration of routes, openapi definitions, etc. and call this function after receive 'bind'/'unbind' events of all loading controllers. |
A short-term workaround for the missing feature tracked by #433 Signed-off-by: Miroslav Bajtoš <[email protected]>
6ce2228 shows a quick fix that may be good enough for short term. For longer term, this feature should use
|
@bajtos, could you please update the ticket with acceptance criteria? Thanks! |
REST server sees all the routes. The context view is a mechanism to watch and refresh. Perhaps this angle should be used to manage the cache. |
I think the recently introduced |
FYI: I added the following "Acceptance Criteria":
|
… is started Implements #433 - use tags to identify regular routes and controller routes - use context observer to watch route related events
… is started Implements #433 - use tags to identify regular routes and controller routes - use context observer to watch route related events
PR #4679 has landed. Closing as done. |
Support hot-reloading of controllers after the app started. See
Application.prototype._setupHandlerIfNeeded()
.Example test case:
Acceptance criteria
When the application binds a controller after the app has started, the application picks up the endpoints contributed by the new controller.
Nice to have:
app.unbind()
API), the endpoints are removed from the REST server and the OpenAPI spec.The text was updated successfully, but these errors were encountered: