OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to inject middleware provider into loopback sequence

  • Thread starter Thread starter Hojjat Jashnniloofar
  • Start date Start date
H

Hojjat Jashnniloofar

Guest
I'm following documentation here and I want to write a middleware in loopback to log all requests. I write this Middleware provider:

Code:
@injectable(
  asMiddleware({
    group: 'log',
    upstreamGroups: ['sendResponse'],
    chain: RestTags.REST_MIDDLEWARE_CHAIN,
  }),
)
export class LogMiddlewareProvider
  implements Provider<Middleware> {
  value(): Middleware {
    return async (ctx, next) => {
      const {request} = ctx
      try {
        console.log(request.method);
        const result = await next();
        return result;
      } catch (err) {
        console.log(err);
        throw err;
      }
    }
  }
}

But I can not find in documentation that how I can use this provider and how can I inject this into sequence or in my application

<p>I'm following documentation <a href="https://loopback.io/doc/en/lb4/REST-middleware-sequence.html" rel="nofollow noreferrer">here</a> and I want to write a middleware in loopback to log all requests.
I write this Middleware provider:</p>
<pre><code>@injectable(
asMiddleware({
group: 'log',
upstreamGroups: ['sendResponse'],
chain: RestTags.REST_MIDDLEWARE_CHAIN,
}),
)
export class LogMiddlewareProvider
implements Provider<Middleware> {
value(): Middleware {
return async (ctx, next) => {
const {request} = ctx
try {
console.log(request.method);
const result = await next();
return result;
} catch (err) {
console.log(err);
throw err;
}
}
}
}
</code></pre>
<p>But I can not find in documentation that how I can use this provider and how can I inject this into sequence or in my application</p>
 

Latest posts

G
Replies
0
Views
1
Gamal Othman
G
Top