Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Wednesday, 31 October 2018 01:47:49 MSK alweiss wrote: > My problem is that services can be one, two … ten etc … so not easy to place > in the callback of the previous subrequest ... > Actually it's not a problem. Here's an example: function authorize(r) { var n = 0; var svcs = ['one

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Ok, got it ! Thanks much Valentin, Maxim and Dmitry for your guidance. I decided to go as the nginx sample (https://www.nginx.com/blog/batching-api-requests-nginx-plus-javascript-module/) with the resp var which is concatened with result of each subrequest : my final_status starts with 403 at init

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
My problem is that services can be one, two … ten etc … so not easy to place in the callback of the previous subrequest ... Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281699,281753#msg-281753 ___ nginx mailing list nginx@nginx.org http:/

Re: Variable scope in javascript module

2018-10-30 Thread Maxim Konovalov
On 31/10/2018 01:27, Valentin V. Bartenev wrote: > On Wednesday, 31 October 2018 00:55:20 MSK you wrote: > [..] > >> However, when i run it, the result is as below : >> The suprising thing is the order it is logged : it seems : as we go for >> async, perhaps both request are started at the same ti

Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Wednesday, 31 October 2018 00:55:20 MSK you wrote: [..] > However, when i run it, the result is as below : > The suprising thing is the order it is logged : it seems : as we go for > async, perhaps both request are started at the same time so each one get a > starting of 403 (no yet updated). C

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Thanks guys, this is a first step. I moved declaration to the top of my script : START SCRIPT * var n = 0; var final_status = 403; var servicesCodes = ['rest','oass']; var requestCount = servicesCodes.length; function authorize(req, res) { req.warn('Variables init ...');

Re: Variable scope in javascript module

2018-10-30 Thread Valentin V. Bartenev
On Tuesday 30 October 2018 12:58:53 alweiss wrote: > Here is a sample that works with Java but not with njs : > > function my() { > resp = "Start"; > console.log ('Initial resp is ' + resp); > > function done() { > resp += "AndContinue"; > console.log('In loop resp is

Re: Variable scope in javascript module

2018-10-30 Thread Dmitry Volyntsev
On 30.10.2018 19:58, alweiss wrote: Here is a sample that works with Java but not with njs : function my() { resp = "Start"; console.log ('Initial resp is ' + resp); function done() { resp += "AndContinue"; console.log('In loop resp is ' + resp) }

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Here is a sample that works with Java but not with njs : function my() { resp = "Start"; console.log ('Initial resp is ' + resp); function done() { resp += "AndContinue"; console.log('In loop resp is ' + resp) } done(); } resp = 'empty' my(); console.log('End

Re: Variable scope in javascript module

2018-10-30 Thread alweiss
Hi Dmitry, thanks for your reply. Here is my code called using js_content authorize; from a location {} I want to say "if at least one subrequest answers HTTP/200, set the final_status to 200 and at then end, return 200" First thing is that i must declare requestCount with var. If i don't, i get

njs 0.2.5 release

2018-10-30 Thread Dmitry Volyntsev
Hello, I'm glad to announce a new release of NGINX JavaScript module (njs). This release proceeds to extend the coverage of ECMAScript 5.1 specification. - arguments object is added. So, it is possible to write functions which can take the arbitrary number of arguments as well as wrapp

Re: large request body in njs

2018-10-30 Thread Jonathan Esterhazy
Yes, these suggestions worked. Thanks! On Oct 30, 2018, 2:14 AM -0700, Dmitry Volyntsev , wrote: > > > > On 29 Oct 2018, at 23:44, Jonathan Esterhazy > > wrote: > > > > Hello! > > > > I am trying to use njs (ngx_http_js_module) to modify POSTed request data > > before sending to an upstream api.

Re: large request body in njs

2018-10-30 Thread Dmitry Volyntsev
> On 29 Oct 2018, at 23:44, Jonathan Esterhazy > wrote: > > Hello! > > I am trying to use njs (ngx_http_js_module) to modify POSTed request data > before sending to an upstream api. Using the req.requestBody function works > fine for small requests, but for larger ones causes this error: >