Open angle319 opened 1 year ago
My solution is using other flag to condition only execution once time.
const guards = this.getGuards(controller.metatype.prototype[key]).map(
(guard) => {
const prototype = guard['prototype'] ?? guard;
const traceName = `Guard->${controller.name}.${controller.metatype.prototype[key].name}.${prototype.constructor.name}`;
const isDerGuard = /[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(prototype.constructor.name)
const guardName = (isDerGuard) ? `Sub-Guard(Auto generate)`: prototype.constructor.name
// same guard will loop overwrite canActivate method
if (!prototype['singleton']) {
prototype.canActivate = this.wrap(
prototype.canActivate,
guardName,
{
controller: controller.name,
guard: prototype.constructor.name,
method: controller.metatype.prototype[key].name,
scope: 'CONTROLLER_METHOD',
},
);
prototype['singleton']=true
}
Object.assign(prototype, this);
this.loggerService.log(
`Mapped ${traceName}`,
this.constructor.name,
);
return guard;
},
);
provide for you, thanks!
Hey owner, I found some problem. It's happend when same guard been use on different controller. my zipkin will receive so many guard event, like following. The root cause is rewrite "canActivate" which been used on guard instance. It will loop rewriting until load all controller.