comparison xml/en/docs/njs/examples.xml @ 2517:ba9bfd064a61

Renamed and corrected example in njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 24 Mar 2020 10:12:27 +0000
parents b60e5be733cd
children 1cd0abf8f1e5
comparison
equal deleted inserted replaced
2516:4ca808544013 2517:ba9bfd064a61
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Examples" 9 <article name="Examples"
10 link="/en/docs/njs/examples.html" 10 link="/en/docs/njs/examples.html"
11 lang="en" 11 lang="en"
12 rev="8"> 12 rev="9">
13 13
14 <section id="helloword" name="Hello World"> 14 <section id="helloword" name="Hello World">
15 15
16 <para> 16 <para>
17 <path>nginx.conf</path>: 17 <path>nginx.conf</path>:
352 </para> 352 </para>
353 353
354 </section> 354 </section>
355 355
356 356
357 <section id="promisified_subrequest" name="Promisified Subrequest"> 357 <section id="subrequests_chaining" name="Subrequests Chaining">
358 358
359 <para> 359 <para>
360 The example works since 360 The example works since
361 <link doc="changes.xml" id="njs0.3.8">0.3.8</link>. 361 <link doc="changes.xml" id="njs0.3.8">0.3.8</link>.
362 <path>nginx.conf</path>: 362 <path>nginx.conf</path>:
363 <example> 363 <example>
364 js_include promisified_subrequest.js; 364 js_include subrequests_chaining.js;
365 365
366 location /start { 366 location /start {
367 js_content content; 367 js_content content;
368 } 368 }
369 369
376 } 376 }
377 </example> 377 </example>
378 </para> 378 </para>
379 379
380 <para> 380 <para>
381 <path>promisified_subrequest.js</path>: 381 <path>subrequests_chaining.js</path>:
382 <example> 382 <example>
383 function content(r) { 383 function content(r) {
384 r.subrequest(r, '/auth') 384 r.subrequest('/auth')
385 .then(reply => JSON.parse(reply.responseBody)) 385 .then(reply => JSON.parse(reply.responseBody))
386 .then(response => { 386 .then(response => {
387 if (!response['token']) { 387 if (!response['token']) {
388 throw new Error("token is not available"); 388 throw new Error("token is not available");
389 } 389 }
390 return token; 390 return reply['token'];
391 }) 391 })
392 .then(token => { 392 .then(token => {
393 r.subrequest('/backend', `token=${token}`) 393 r.subrequest('/backend', `token=${token}`)
394 .then(reply => r.return(reply.status, reply.responseBody)); 394 .then(reply => r.return(reply.status, reply.responseBody));
395 }) 395 })