Mercurial > hg > nginx-site
comparison xml/ru/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="Модуль ngx_http_js_module" | 9 <module name="Модуль ngx_http_js_module" |
10 link="/ru/docs/http/ngx_http_js_module.html" | 10 link="/ru/docs/http/ngx_http_js_module.html" |
11 lang="ru" | 11 lang="ru" |
12 rev="30"> | 12 rev="31"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 Модуль <literal>ngx_http_js_module</literal> позволяет задавать | 17 Модуль <literal>ngx_http_js_module</literal> позволяет задавать |
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 / { |
53 } | 54 } |
54 | 55 |
55 location = /hello { | 56 location = /hello { |
56 js_content http.hello; | 57 js_content http.hello; |
57 } | 58 } |
59 | |
60 # начиная с версии 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 # начиная с версии 0.7.0 | |
67 location = /crypto { | |
68 add_header Hash $hash; | |
69 return 200; | |
70 } | |
58 } | 71 } |
59 } | 72 } |
60 </example> | 73 </example> |
61 </para> | 74 </para> |
62 | 75 |
63 <para> | 76 <para> |
64 The <path>http.js</path> file: | 77 Файл <path>http.js</path>: |
65 <example> | 78 <example> |
66 function foo(r) { | 79 function foo(r) { |
67 r.log("hello from foo() handler"); | 80 r.log("hello from foo() handler"); |
68 return "foo"; | 81 return "foo"; |
69 } | 82 } |
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 // начиная с версии 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 // начиная с версии 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 |