diff xml/en/docs/http/ngx_http_js_module.xml @ 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 a2852750c379
children 65591dd31d64
line wrap: on
line diff
--- a/xml/en/docs/http/ngx_http_js_module.xml
+++ b/xml/en/docs/http/ngx_http_js_module.xml
@@ -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 @@ http {
 
     js_set $foo     http.foo;
     js_set $summary http.summary;
+    js_set $hash    http.hash;
 
     server {
         listen 8000;
@@ -55,6 +56,18 @@ http {
         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 @@ function hello(r) {
     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>