Mercurial > hg > nginx-site
diff xml/ru/docs/njs/reference.xml @ 2290:65c6c1ee3c78
Removed obsolete "Examples" section from Russian njs reference.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 27 Nov 2018 19:04:53 +0300 |
parents | 32ba43abf9cd |
children | a1d0238ffb61 |
line wrap: on
line diff
--- a/xml/ru/docs/njs/reference.xml Tue Nov 27 19:04:53 2018 +0300 +++ b/xml/ru/docs/njs/reference.xml Tue Nov 27 19:04:53 2018 +0300 @@ -292,234 +292,5 @@ </section> - -<section id="example" name="Примеры"> - - -<section id="example_urldecode" name="Декодирование URL"> - -<para> -<example> -js_include urldecode.js; - -js_set $decoded_foo decoded_foo; -</example> -</para> - -<para> -Файл <path>urldecode.js</path>: -<example> -function decoded_foo(r) { - return decodeURIComponent(r.args.foo); -} -</example> -</para> - -</section> - - -<section id="example_urlencode" name="Кодирование URL"> - -<para> -<example> -js_include urlencode.js; - -js_set $encoded_foo encoded_foo; -... - -location / { - proxy_pass http://example.com?foo=$encoded_foo; -} -</example> -</para> - -<para> -Файл <path>urlencode.js</path>: -<example> -function encoded_foo(r) { - return encodeURIComponent('foo & bar?'); -} -</example> -</para> - -</section> - - -<section id="example_fast_response" name="Возврат самого быстрого ответа от прокси"> - -<para> -<example> -js_include fastresponse.js; - -location /start { - js_content content; -} - -location /foo { - proxy_pass http://backend1; -} - -location /bar { - proxy_pass http://backend2; -} -</example> -</para> - -<para> -Файл <path>fastresponse.js</path>: -<example> -function content(r) { - var n = 0; - - function done(res) { - if (n++ == 0) { - r.return(res.status, res.responseBody); - } - } - - r.subrequest('/foo', r.variables.args, done); - r.subrequest('/bar', r.variables.args, done);TBD -} -</example> -</para> - -</section> - - -<section id="example_jwt" name="Создание HS JWT"> - -<para> -<example> -js_include hs_jwt.js; - -js_set $jwt jwt; -</example> -</para> - -<para> -Файл <path>hs_jwt.js</path>: -<example> -function create_hs256_jwt(claims, key, valid) { - var header = { "typ" : "JWT", "alg" : "HS256", "exp" : Date.now() + valid }; - - var s = JSON.stringify(header).toBytes().toString('base64url') + '.' - + JSON.stringify(claims).toBytes().toString('base64url'); - - var h = require('crypto').createHmac('sha256', key); - - return s + '.' + h.update(s).digest().toString('base64url'); -} - -function jwt(r) { - var claims = { - "iss" : "nginx", - "sub" : "alice", - "foo" : 123, - "bar" : "qq", - "zyx" : false - }; - - return create_hs256_jwt(claims, 'foo', 600); -} -</example> -</para> - -</section> - - -<section id="example_subrequest" name="Доступ к API при помощи подзапроса"> - -<para> -<example> -js_include subrequest.js; - -keyval_zone zone=foo:10m; -... - -location /keyval { - js_content set_keyval; -} - -location /version { - js_content version; -} - -location /api { - api write=on; -} -</example> -</para> - -<para> -Файл <path>subrequest.js</path>: -<example> -function set_keyval(r) { - r.subrequest('/api/3/http/keyvals/foo', - { method: 'POST', - body: JSON.stringify({ foo: 789, bar: "ss dd 00" })}, - - function(res) { - if (res.status >= 300) { - r.return(res.status, res.responseBody); - return; - } - r.return(500); - }); -} - -function version(r) { - r.subrequest('/api/3/nginx', { method: 'GET' }, function(res) { - if (res.status != 200) { - r.return(res.status); - return; - } - - var json = JSON.parse(res.responseBody); - r.return(200, json.version); - }); -} -</example> -</para> - -</section> - - -<section id="example_secure_link" name="Создание хэша secure_link"> - -<para> -<example> -js_include hash.js; - -js_set $new_foo create_secure_link; -... - -location / { - secure_link $cookie_foo; - secure_link_md5 "$uri mykey"; - ... -} - -location @login { - add_header Set-Cookie "foo=$new_foo; Max-Age=60"; - return 302 /; -} -</example> -</para> - -<para> -Файл <path>hash.js</path>: -<example> -function create_secure_link(r) { - return require('crypto').createHash('md5') - .update(r.uri).update(" mykey") - .digest('base64url'); -} -</example> -</para> - -</section> - -</section> - </article>