# HG changeset patch # User Yaroslav Zhuravlev # Date 1611135272 0 # Node ID c60bcc0de4356793af6f4db9460d2e87f5cbfd36 # Parent ea9f4dc0c80167f6e23c722b5dc8cf3180f9ac14 Updated TOC in njs examples. diff -r ea9f4dc0c801 -r c60bcc0de435 xml/en/docs/njs/examples.xml --- a/xml/en/docs/njs/examples.xml Thu Jan 21 12:12:47 2021 +0000 +++ b/xml/en/docs/njs/examples.xml Wed Jan 20 09:34:32 2021 +0000 @@ -56,134 +56,7 @@ -
- - -nginx.conf: - -js_import http.js; - -js_set $decoded_foo http.decoded_foo; - - - - -http.js: - -function decoded_foo(r) { - return decodeURIComponent(r.args.foo); -} - -export default {decoded_foo}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -js_set $encoded_foo http.encoded_foo; -... - -location / { - proxy_pass http://example.com?foo=$encoded_foo; -} - - - - -http.js: - -function encoded_foo(r) { - return encodeURIComponent('foo & bar?'); -} - -export default {encoded_foo}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -location /redirect { - js_content http.redirect; -} - -location @named { - return 200 named; -} - - - - -http.js: - -function redirect(r) { - r.internalRedirect('@named'); -} - -export default {redirect}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -location /start { - js_content http.content; -} - -location /foo { - proxy_pass http://backend1; -} - -location /bar { - proxy_pass http://backend2; -} - - - - -http.js: - -function content(r) { - var n = 0; - - function done(res) { - if (n++ == 0) { - r.return(res.status, res.responseBody); - } - } - - r.subrequest('/foo', r.variables.args, done); - r.subrequest('/bar', r.variables.args, done); -} - -export default {content}; - - - -
+
@@ -232,6 +105,45 @@
+ + +
@@ -272,6 +184,11 @@
+
+ + +
+
@@ -333,25 +250,23 @@
- + + +
+ + +
+ + +nginx.conf: + +js_import http.js; + +location /redirect { + js_content http.redirect; +} + +location @named { + return 200 named; +} + + + + +http.js: + +function redirect(r) { + r.internalRedirect('@named'); +} + +export default {redirect}; @@ -421,24 +426,43 @@
- -
+
nginx.conf: js_import http.js; -location /start { - js_content http.content; +js_set $decoded_foo http.decoded_foo; + + + + +http.js: + +function decoded_foo(r) { + return decodeURIComponent(r.args.foo); } -location /auth { - proxy_pass http://auth_backend; -} +export default {decoded_foo}; + + + +
+ + +
-location /backend { - proxy_pass http://backend; + +nginx.conf: + +js_import http.js; + +js_set $encoded_foo http.encoded_foo; +... + +location / { + proxy_pass http://example.com?foo=$encoded_foo; } @@ -446,26 +470,16 @@ http.js: -function content(r) { - r.subrequest('/auth') - .then(reply => JSON.parse(reply.responseBody)) - .then(response => { - if (!response['token']) { - throw new Error("token is not available"); - } - return reply['token']; - }) - .then(token => { - r.subrequest('/backend', `token=${token}`) - .then(reply => r.return(reply.status, reply.responseBody)); - }) - .catch(_ => r.return(500)); +function encoded_foo(r) { + return encodeURIComponent('foo & bar?'); } -export default {content}; +export default {encoded_foo};
+
+ diff -r ea9f4dc0c801 -r c60bcc0de435 xml/ru/docs/njs/examples.xml --- a/xml/ru/docs/njs/examples.xml Thu Jan 21 12:12:47 2021 +0000 +++ b/xml/ru/docs/njs/examples.xml Wed Jan 20 09:34:32 2021 +0000 @@ -55,134 +55,7 @@
-
- - -nginx.conf: - -js_import http.js; - -js_set $decoded_foo http.decoded_foo; - - - - -http.js: - -function decoded_foo(r) { - return decodeURIComponent(r.args.foo); -} - -export default {decoded_foo}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -js_set $encoded_foo http.encoded_foo; -... - -location / { - proxy_pass http://example.com?foo=$encoded_foo; -} - - - - -http.js: - -function encoded_foo(r) { - return encodeURIComponent('foo & bar?'); -} - -export default {encoded_foo}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -location /redirect { - js_content http.redirect; -} - -location @named { - return 200 named; -} - - - - -http.js: - -function redirect(r) { - r.internalRedirect('@named'); -} - -export default {redirect}; - - - -
- - -
- - -nginx.conf: - -js_import http.js; - -location /start { - js_content http.content; -} - -location /foo { - proxy_pass http://backend1; -} - -location /bar { - proxy_pass http://backend2; -} - - - - -http.js: - -function content(r) { - var n = 0; - - function done(res) { - if (n++ == 0) { - r.return(res.status, res.responseBody); - } - } - - r.subrequest('/foo', r.variables.args, done); - r.subrequest('/bar', r.variables.args, done); -} - -export default {content}; - - - -
+
@@ -231,6 +104,45 @@
+ + +
@@ -271,6 +183,11 @@
+
+ + +
+
@@ -332,25 +249,23 @@
- + + +
+ + +
+ + +nginx.conf: + +js_import http.js; + +location /redirect { + js_content http.redirect; +} + +location @named { + return 200 named; +} + + + + +http.js: + +function redirect(r) { + r.internalRedirect('@named'); +} + +export default {redirect}; + + + +
+
@@ -421,23 +425,43 @@
-
+
nginx.conf: js_import http.js; -location /start { - js_content http.content; +js_set $decoded_foo http.decoded_foo; + + + + +http.js: + +function decoded_foo(r) { + return decodeURIComponent(r.args.foo); } -location /auth { - proxy_pass http://auth_backend; -} +export default {decoded_foo}; + + + +
+ + +
-location /backend { - proxy_pass http://backend; + +nginx.conf: + +js_import http.js; + +js_set $encoded_foo http.encoded_foo; +... + +location / { + proxy_pass http://example.com?foo=$encoded_foo; } @@ -445,26 +469,16 @@ http.js: -function content(r) { - r.subrequest('/auth') - .then(reply => JSON.parse(reply.responseBody)) - .then(response => { - if (!response['token']) { - throw new Error("token is not available"); - } - return reply['token']; - }) - .then(token => { - r.subrequest('/backend', `token=${token}`) - .then(reply => r.return(reply.status, reply.responseBody)); - }) - .catch(_ => r.return(500)); +function encoded_foo(r) { + return encodeURIComponent('foo & bar?'); } -export default {content}; +export default {encoded_foo};
+
+