moleculerjs / moleculer

:rocket: Progressive microservices framework for Node.js
https://moleculer.services/
MIT License
6.14k stars 582 forks source link

using grunt.loadNpmTasks('grunt-contrib-obfuscator') cause service event context lost, always undefind #1285

Closed lling1105 closed 4 months ago

lling1105 commented 4 months ago

Current Behavior

if not using grunt-contrib-obfuscator, every service is working well. after obfuscator, action and method are working well,but the event method received ctx only has param property, other ctx property lost

Expected Behavior

use grunt-contrib-obfuscator to obfus the codes and working well.

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

icebob commented 4 months ago

Moleculer tries to detect the event handler signature, but if the property name is not ctx it uses as a non-context signature. You can force the context signature mode with context: true in event properties, like here:

image

lling1105 commented 4 months ago

Moleculer tries to detect the event handler signature, but if the property name is not ctx it uses as a non-context signature. You can force the context signature mode with context: true in event properties, like here:

image

thanks much @icebob for your reply! the same time i also find another solution is set the obfus options as below and working well

options:{
                reservedNames: ['context','ctx'],
                reservedStrings: ['context','ctx']
}