You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Migration help: Can Interceptors work with mouted lb3 application? #6099
I have one LB3 project with operation hook function used: .afterRemote and .observe('before save'.
LoopBack 4 new solution
I am referring to this toturial: https://loopback.io/doc/en/lb4/migration-mounting-lb3app.html for migration now.
The good news is that Swagger API is working after the migration.
Unfortunally, I find the operation hook will not work anymore after I mount LB3 project as a component in LB4.
And there's interceptors will take the role of operation hooks, But it seems inteceptors is only working with LB4 Controllers and handler functions for REST routes.
Is that possible LB4 interceptors can work with mouted LB3 application? Or am I misunderstanding the LB4 interceptors use case?
Not sure if we can configure my global interceptor to app in the index.ts. I did't find a good example to explain the
@dhmlau Thank you so much for your reply.
Currently I only have loopback 3 models, does that mean I need to rewrite the loopback 4 repository for loopback 3 models to make the operation hooks function work?
The perferred option is that no more code for rewriting the loopback 3 models and only the remoting/operation hooks will be implemente with Loopback 4 manner. Is that feasible? I would not like to rewrite it, because It will take too much effort to rewrite the whole thing if I need to use LB4 repository instead of LB3 models(in lb3app).
Hi, sorry for the delayed response. If you want to use a global interceptor, try using the lb4 interceptor command e.g.
$ lb4 interceptor
? Interceptor name: global
? Is it a global interceptor? Yes
Global interceptors are sorted by the order of an array of group names bound to ContextBindings.GLOBAL_INTERCEPTOR_ORDERED_GROUPS. See https://loopback.io/doc/en/lb4/Interceptors.html#order-of-invocation-for-interceptors.
? Group name for the global interceptor: ('')
create src/interceptors/global.interceptor.ts
update src/interceptors/index.ts
Interceptor Global was/were created in src/interceptors
In the created src/interceptors/global.interceptor.ts (or whatever you name it) file, you can add your logic there.
Thanks @QPierre1! I think we can document the middleware workaround you're using for now and then we'll have to see if we can get lb4 interceptors to also work for lb3 routes. Would you be interested in doing the documentation portion?
Activity
dhmlau commentedon Aug 13, 2020
@dzhiwei, I believe the closest migration path for the operation hooks is to override the
definePersistedModelmethod in DefaultCrudRepository in the model’s repository. You can find more details in: https://loopback.io/doc/en/lb4/migration-models-operation-hooks.html.dzhiwei commentedon Aug 13, 2020
@dhmlau Thank you so much for your reply.
Currently I only have loopback 3 models, does that mean I need to rewrite the loopback 4 repository for loopback 3 models to make the operation hooks function work?
The perferred option is that no more code for rewriting the loopback 3 models and only the remoting/operation hooks will be implemente with Loopback 4 manner. Is that feasible? I would not like to rewrite it, because It will take too much effort to rewrite the whole thing if I need to use LB4 repository instead of LB3 models(in
lb3app).dhmlau commentedon Aug 17, 2020
@hacksparrow @nabdelgadir, do you think you can help with the question since you both were working on the mounting LB3 app guides? Thanks.
nabdelgadir commentedon Aug 23, 2020
Hi, sorry for the delayed response. If you want to use a global interceptor, try using the
lb4 interceptorcommand e.g.In the created
src/interceptors/global.interceptor.ts(or whatever you name it) file, you can add your logic there.Let us know if this works for you. Thanks!
dhmlau commentedon Sep 11, 2020
@dzhiwei, we believe we've answered your question. Closing this issue. Thanks.
Quent1Pr commentedon Nov 25, 2020
I try a global interceptor but it only intercepts lb4 queries and not lb3 queries.
I found a workaround with a lb4 middleware : https://loopback.io/doc/en/lb4/Middleware.html#loopback-style-middleware
nabdelgadir commentedon Nov 25, 2020
Thanks @QPierre1! I think we can document the middleware workaround you're using for now and then we'll have to see if we can get lb4 interceptors to also work for lb3 routes. Would you be interested in doing the documentation portion?
Propose a tip to intercept all queries
Doc: Propose a tip to intercept all queries
docs: Propose a tip to intercept all queries
docs: tip to intercept all queries
docs: tip to intercept all queries
docs: tip to intercept all queries
docs: tip to intercept all queries