flomesh-io / pipy

Pipy is a programmable proxy for the cloud, edge and IoT.
https://flomesh.io/pipy
Other
743 stars 70 forks source link

it seems pipyjs not implement JSON.parse(text, recevier?) ,recevier not work. #143

Closed chungang-li closed 1 year ago

chungang-li commented 1 year ago

.pipeline('notify-pipeline') // .onStart(()=> void(console.log('module====>(pipeline)[notify-pipeline]'))) .branch( () => Boolean(serviceObj.notify_services && __serviceObj.notify_services?.length > 0), ( $=>$.fork(() => serviceObj.notify_services).to( $=>$.onStart(r => void(console.log('on-start-invoked', r) , _nextService = r)) .replaceMessage( e => ( (route, path, headers, body) => ( _target = _services[_nextService].select(), path = e.head.path, body = JSON.parse(e.body.toString(), (k,v)=>( console.log(v), // not work v )), new Message({ ...e.head, path: path, headers }, JSON.stringify(body? body : '') ) ) )() ).link( 'forward', () => Boolean(_target), 'bypass' ) ) ), )

pajama-coder commented 1 year ago

Yes, the reviver parameter is currently not supported. I'll make time to implement it if it's a much needed feature.

btw. You can always change "JSON.parse(data.toString())" to "JSON.decode(data)" safely and get a performance boost due to the unnecessary string conversion by toString().

pajama-coder commented 1 year ago

@chungang-li The reviver parameter is now implemented for JSON.parse() and JSON.decode() since commit 3911ed68ccda425950270ea566c11c8d8095ac49. You can use it in the latest nightly build or wait until the next major release.

keveinliu commented 1 year ago

@chungang-li Hello, could you please help verify if it resolves your issue? Thanks!

chungang-li commented 1 year ago

I've solved it in other ways,i will try it in the Next Major release . tks