Hi, I am searching for a middleware implement for our project. The solution looks promising.
In our case, sometimes, the middleware need to know some context information to fulfill its task. So, I am wondering if it's possible to enable inject some extra argument to middleware to make the information available.
The proposal looks like:
// middleware constructor
// @param {object} extraArgument - data will be injected into middleware
constructor(target, extraArgument, ...middlewareObjects)
// middleware _applyToMethod
middlewares.forEach(middleware =>
typeof middleware === 'function' &&
this._methodMiddlewares[methodName].push(middleware(this._target, this._extraArgument))
);
// middleware implementation
const walk = (target, extraArgument) => next => (...args) => {
// the extraArgument is now accessible in the middleware implementation
return result;
}
Hi, I am searching for a
middlewareimplement for our project. The solution looks promising.In our case, sometimes, the middleware need to know some context information to fulfill its task. So, I am wondering if it's possible to enable inject some extra argument to middleware to make the information available.
The proposal looks like: