comparison 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
comparison
equal deleted inserted replaced
2778:9cafae0b7ef3 2779:b6bbdce8c659
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> 7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
8 8
9 <module name="Module ngx_http_js_module" 9 <module name="Module ngx_http_js_module"
10 link="/en/docs/http/ngx_http_js_module.html" 10 link="/en/docs/http/ngx_http_js_module.html"
11 lang="en" 11 lang="en"
12 rev="30"> 12 rev="31">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The <literal>ngx_http_js_module</literal> module is used to implement 17 The <literal>ngx_http_js_module</literal> module is used to implement
37 http { 37 http {
38 js_import http.js; 38 js_import http.js;
39 39
40 js_set $foo http.foo; 40 js_set $foo http.foo;
41 js_set $summary http.summary; 41 js_set $summary http.summary;
42 js_set $hash http.hash;
42 43
43 server { 44 server {
44 listen 8000; 45 listen 8000;
45 46
46 location / { 47 location / {
52 return 200 $summary; 53 return 200 $summary;
53 } 54 }
54 55
55 location = /hello { 56 location = /hello {
56 js_content http.hello; 57 js_content http.hello;
58 }
59
60 # since 0.7.0
61 location = /fetch {
62 js_content http.fetch;
63 js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
64 }
65
66 # since 0.7.0
67 location = /crypto {
68 add_header Hash $hash;
69 return 200;
57 } 70 }
58 } 71 }
59 } 72 }
60 </example> 73 </example>
61 </para> 74 </para>
107 120
108 function hello(r) { 121 function hello(r) {
109 r.return(200, "Hello world!"); 122 r.return(200, "Hello world!");
110 } 123 }
111 124
112 export default {foo, summary, baz, hello}; 125 // since 0.7.0
126 async function fetch(r) {
127 let results = await Promise.all([ngx.fetch('http://nginx.org/'),
128 ngx.fetch('http://nginx.org/en/')]);
129
130 r.return(200, JSON.stringify(results, undefined, 4));
131 }
132
133 // since 0.7.0
134 async function hash(r) {
135 let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
136 r.setReturnValue(Buffer.from(hash).toString('hex'));
137 }
138
139 export default {foo, summary, baz, hello, fetch, hash};
113 </example> 140 </example>
114 </para> 141 </para>
115 142
116 </section> 143 </section>
117 144