comparison xml/en/docs/njs/examples.xml @ 2778:9cafae0b7ef3

Minor fixes in njs examples.
author Yaroslav Zhuravlev <yar@nginx.com>
date Thu, 14 Oct 2021 18:53:16 +0100
parents 4849fa0fd4b4
children bf641527bd3d
comparison
equal deleted inserted replaced
2777:bc79ab31073a 2778:9cafae0b7ef3
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Examples" 9 <article name="Examples"
10 link="/en/docs/njs/examples.html" 10 link="/en/docs/njs/examples.html"
11 lang="en" 11 lang="en"
12 rev="18"> 12 rev="19">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The examples work since 17 The examples work since
111 <path>nginx.conf</path>: 111 <path>nginx.conf</path>:
112 <example> 112 <example>
113 js_import http.js; 113 js_import http.js;
114 114
115 js_set $new_foo http.create_secure_link; 115 js_set $new_foo http.create_secure_link;
116 ... 116 #...
117 117
118 location / { 118 location / {
119 secure_link $cookie_foo; 119 secure_link $cookie_foo;
120 secure_link_md5 "$uri mykey"; 120 secure_link_md5 "$uri mykey";
121 ... 121 #
122 } 122 }
123 123
124 location @login { 124 location @login {
125 add_header Set-Cookie "foo=$new_foo; Max-Age=60"; 125 add_header Set-Cookie "foo=$new_foo; Max-Age=60";
126 return 302 /; 126 return 302 /;
150 <para> 150 <para>
151 <path>nginx.conf</path>: 151 <path>nginx.conf</path>:
152 <example> 152 <example>
153 js_import http.js; 153 js_import http.js;
154 154
155 js_set $jwt_payload_sub main.jwt_payload_sub; 155 js_set $jwt_payload_sub http.jwt_payload_sub;
156 156
157 server { 157 server {
158 ... 158 #...
159 159
160 location /jwt { 160 location /jwt {
161 return 200 $jwt_payload_sub; 161 return 200 $jwt_payload_sub;
162 } 162 }
163 } 163 }
176 176
177 function jwt_payload_sub(r) { 177 function jwt_payload_sub(r) {
178 return jwt(r.headersIn.Authorization.slice(7)).payload.sub; 178 return jwt(r.headersIn.Authorization.slice(7)).payload.sub;
179 } 179 }
180 180
181 export default {jwt_payload_sub} 181 export default {jwt_payload_sub};
182 </example> 182 </example>
183 </para> 183 </para>
184 184
185 </section> 185 </section>
186 186
196 <path>nginx.conf</path>: 196 <path>nginx.conf</path>:
197 <example> 197 <example>
198 js_import http.js; 198 js_import http.js;
199 199
200 keyval_zone zone=foo:10m; 200 keyval_zone zone=foo:10m;
201 ... 201 #...
202 202
203 location /keyval { 203 location /keyval {
204 js_content http.set_keyval; 204 js_content http.set_keyval;
205 } 205 }
206 206
216 216
217 <para> 217 <para>
218 <path>http.js</path>: 218 <path>http.js</path>:
219 <example> 219 <example>
220 function set_keyval(r) { 220 function set_keyval(r) {
221 r.subrequest('/api/5/http/keyvals/foo', 221 r.subrequest('/api/7/http/keyvals/foo',
222 { method: 'POST', 222 { method: 'POST',
223 body: JSON.stringify({ foo: 789, bar: "ss dd 00" })}, 223 body: JSON.stringify({ foo: 789, bar: "ss dd 00" })},
224 224
225 function(res) { 225 function(res) {
226 if (res.status >= 300) { 226 if (res.status >= 300) {
230 r.return(500); 230 r.return(500);
231 }); 231 });
232 } 232 }
233 233
234 function version(r) { 234 function version(r) {
235 r.subrequest('/api/5/nginx', { method: 'GET' }, function(res) { 235 r.subrequest('/api/7/nginx', { method: 'GET' }, function(res) {
236 if (res.status != 200) { 236 if (res.status != 200) {
237 r.return(res.status); 237 r.return(res.status);
238 return; 238 return;
239 } 239 }
240 240
243 }); 243 });
244 } 244 }
245 245
246 export default {set_keyval, version}; 246 export default {set_keyval, version};
247 </example> 247 </example>
248 <note>
249 The <link doc="../http/ngx_http_keyval_module.xml" id="keyval"/>,
250 <link doc="../http/ngx_http_keyval_module.xml" id="keyval_zone"/>,
251 and <link doc="../http/ngx_http_api_module.xml" id="api"/> directives
252 are available as part of our
253 <commercial_version>commercial subscription</commercial_version>.
254 </note>
248 </para> 255 </para>
249 256
250 </section> 257 </section>
251 258
252 259