changeset 2779:b6bbdce8c659

Updated Example Configuration in ngx_http_js_module.
author Yaroslav Zhuravlev <yar@nginx.com>
date Fri, 15 Oct 2021 20:13:02 +0100
parents 9cafae0b7ef3
children bf641527bd3d
files xml/en/docs/http/ngx_http_js_module.xml xml/ru/docs/http/ngx_http_js_module.xml
diffstat 2 files changed, 59 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/xml/en/docs/http/ngx_http_js_module.xml	Thu Oct 14 18:53:16 2021 +0100
+++ b/xml/en/docs/http/ngx_http_js_module.xml	Fri Oct 15 20:13:02 2021 +0100
@@ -9,7 +9,7 @@
 <module name="Module ngx_http_js_module"
         link="/en/docs/http/ngx_http_js_module.html"
         lang="en"
-        rev="30">
+        rev="31">
 
 <section id="summary">
 
@@ -39,6 +39,7 @@
 
     js_set $foo     http.foo;
     js_set $summary http.summary;
+    js_set $hash    http.hash;
 
     server {
         listen 8000;
@@ -55,6 +56,18 @@
         location = /hello {
             js_content http.hello;
         }
+
+        # since 0.7.0
+        location = /fetch {
+            js_content                   http.fetch;
+            js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
+        }
+
+        # since 0.7.0
+        location = /crypto {
+            add_header Hash $hash;
+            return     200;
+        }
     }
 }
 </example>
@@ -109,7 +122,21 @@
     r.return(200, "Hello world!");
 }
 
-export default {foo, summary, baz, hello};
+// since 0.7.0
+async function fetch(r) {
+    let results = await Promise.all([ngx.fetch('http://nginx.org/'),
+                                     ngx.fetch('http://nginx.org/en/')]);
+
+    r.return(200, JSON.stringify(results, undefined, 4));
+}
+
+// since 0.7.0
+async function hash(r) {
+    let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
+    r.setReturnValue(Buffer.from(hash).toString('hex'));
+}
+
+export default {foo, summary, baz, hello, fetch, hash};
 </example>
 </para>
 
--- a/xml/ru/docs/http/ngx_http_js_module.xml	Thu Oct 14 18:53:16 2021 +0100
+++ b/xml/ru/docs/http/ngx_http_js_module.xml	Fri Oct 15 20:13:02 2021 +0100
@@ -9,7 +9,7 @@
 <module name="Модуль ngx_http_js_module"
         link="/ru/docs/http/ngx_http_js_module.html"
         lang="ru"
-        rev="30">
+        rev="31">
 
 <section id="summary">
 
@@ -39,6 +39,7 @@
 
     js_set $foo     http.foo;
     js_set $summary http.summary;
+    js_set $hash    http.hash;
 
     server {
         listen 8000;
@@ -55,13 +56,25 @@
         location = /hello {
             js_content http.hello;
         }
+
+        # начиная с версии 0.7.0
+        location = /fetch {
+            js_content                   http.fetch;
+            js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
+        }
+
+        # начиная с версии 0.7.0
+        location = /crypto {
+            add_header Hash $hash;
+            return     200;
+        }
     }
 }
 </example>
 </para>
 
 <para>
-The <path>http.js</path> file:
+Файл <path>http.js</path>:
 <example>
 function foo(r) {
     r.log("hello from foo() handler");
@@ -109,7 +122,21 @@
     r.return(200, "Hello world!");
 }
 
-export default {foo, summary, baz, hello};
+// начиная с версии 0.7.0
+async function fetch(r) {
+    let results = await Promise.all([ngx.fetch('http://nginx.org/'),
+                                     ngx.fetch('http://nginx.org/en/')]);
+
+    r.return(200, JSON.stringify(results, undefined, 4));
+}
+
+// начиная с версии 0.7.0
+async function hash(r) {
+    let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
+    r.setReturnValue(Buffer.from(hash).toString('hex'));
+}
+
+export default {foo, summary, baz, hello, fetch, hash};
 </example>
 </para>