annotate xml/ru/docs/stream/ngx_stream_js_module.xml @ 2649:7517de030c0a

Corrected njs example in ngx_stream_js_module module.
author Yaroslav Zhuravlev <yar@nginx.com>
date Wed, 03 Feb 2021 15:45:41 +0000
parents ea9f4dc0c801
children 8751cab1d562
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
1 <?xml version="1.0"?>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
2
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
3 <!--
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
4 Copyright (C) Nginx, Inc.
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
5 -->
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
6
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
8
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
9 <module name="Модуль ngx_stream_js_module"
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
10 link="/ru/docs/stream/ngx_stream_js_module.html"
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
11 lang="ru"
2649
7517de030c0a Corrected njs example in ngx_stream_js_module module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2641
diff changeset
12 rev="23">
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
13
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
14 <section id="summary">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
15
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
16 <para>
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
17 Модуль <literal>ngx_stream_js_module</literal> позволяет задавать
2245
87a0e2c73a25 Refactored njs documentation.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2244
diff changeset
18 обработчики на <link doc="../njs/index.xml">njs</link> —
1844
f56626ce9c40 Changed JavaScript to nginScript.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1843
diff changeset
19 подмножестве языка JavaScript.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
20 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
21
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
22 <para>
2188
523dc4cc8745 Updated installation procedure in njs modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
23 Инструкция по сборке и установке доступны
2245
87a0e2c73a25 Refactored njs documentation.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2244
diff changeset
24 <link doc="../njs/install.xml">здесь</link>.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
25 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
26
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
27 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
28
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
29
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
30 <section id="example" name="Пример конфигурации">
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
31
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
32 <para>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
33 Пример работает начиная с версии
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
34 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
35 <example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
36 stream {
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
37 js_import stream.js;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
38
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
39 js_set $bar stream.bar;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
40 js_set $req_line stream.req_line;
1858
36cbfff92c6d Restricted context of js_set directive to http and stream only.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1853
diff changeset
41
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
42 server {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
43 listen 12345;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
44
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
45 js_preread stream.preread;
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
46 return $req_line;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
47 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
48
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
49 server {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
50 listen 12346;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
51
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
52 js_access stream.access;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
53 proxy_pass 127.0.0.1:8000;
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
54 js_filter stream.header_inject;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
55 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
56 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
57
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
58 http {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
59 server {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
60 listen 8000;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
61 location / {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
62 return 200 $http_foo\n;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
63 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
64 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
65 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
66 </example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
67 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
68
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
69 <para>
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
70 Файл <path>stream.js</path>:
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
71 <example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
72 var line = '';
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
73
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
74 function bar(s) {
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
75 var v = s.variables;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
76 s.log("hello from bar() handler!");
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
77 return "bar-var" + v.remote_port + "; pid=" + v.pid;
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
78 }
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
79
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
80 function preread(s) {
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
81 s.on('upload', function (data, flags) {
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
82 var n = data.indexOf('\n');
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
83 if (n != -1) {
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
84 line = data.substr(0, n);
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
85 s.done();
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
86 }
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
87 });
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
88 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
89
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
90 function req_line(s) {
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
91 return line;
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
92 }
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
93
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
94 // Чтение строки HTTP-запроса.
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
95 // Получение байт в 'req' до того как
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
96 // будет прочитана строка запроса.
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
97 // Добавление HTTP-заголовка в запрос клиента
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
98
2288
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
99 var my_header = 'Foo: foo';
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
100 function header_inject(s) {
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
101 var req = '';
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
102 s.on('upload', function(data, flags) {
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
103 req += data;
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
104 var n = req.search('\n');
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
105 if (n != -1) {
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
106 var rest = req.substr(n + 1);
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
107 req = req.substr(0, n + 1);
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
108 s.send(req + my_header + '\r\n' + rest, flags);
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
109 s.off('upload');
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
110 }
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
111 });
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
112 }
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
113
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
114 function access(s) {
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
115 if (s.remoteAddress.match('^192.*')) {
2649
7517de030c0a Corrected njs example in ngx_stream_js_module module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2641
diff changeset
116 s.deny();
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
117 return;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
118 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
119
2237
5268c13196f2 Documented njs changes triggered by njs-0.2.4.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2190
diff changeset
120 s.allow();
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
121 }
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
122
2641
ea9f4dc0c801 Fixed example in stream js module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2591
diff changeset
123 export default {bar, preread, req_line, header_inject, access};
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
124 </example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
125 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
126
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
127 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
128
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
129
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
130 <section id="directives" name="Директивы">
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
131
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
132 <directive name="js_access">
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
133 <syntax><value>функция</value> | <value>модуль.функция</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
134 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
135 <context>stream</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
136 <context>server</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
137
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
138 <para>
2128
59a3cc84f507 Renamed nginScript to njs
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2026
diff changeset
139 Задаёт функцию njs, которая будет вызываться в
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
140 <link doc="stream_processing.xml" id="access_phase">access</link>-фазе.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
141 Начиная с <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
142 можно ссылаться на функцию модуля.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
143 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
144
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
145 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
146
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
147
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
148 <directive name="js_filter">
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
149 <syntax><value>функция</value> | <value>модуль.функция</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
150 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
151 <context>stream</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
152 <context>server</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
153
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
154 <para>
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
155 Задаёт фильтр данных.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
156 Начиная с <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
157 можно ссылаться на функцию модуля.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
158 </para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
159
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
160 </directive>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
161
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
162
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
163 <directive name="js_import">
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
164 <syntax><value>модуль.js</value> |
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
165 <value>имя_экспорта из модуль.js</value></syntax>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
166 <default/>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
167 <context>stream</context>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
168 <appeared-in>0.4.0</appeared-in>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
169
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
170 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
171 Импортирует модуль, позволяющий задавать обработчики location и переменных
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
172 на njs.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
173 <literal>Имя_экспорта</literal> является пространством имён
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
174 при доступе к функциям модуля.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
175 Если <literal>имя_экспорта</literal> не задано,
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
176 то пространством имён будет являться имя модуля.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
177 <example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
178 js_import stream.js;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
179 </example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
180 В примере при доступе к экспорту в качестве
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
181 пространства имён используется имя модуля <literal>stream</literal>.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
182 Если импортируемый модуль содержит <literal>foo()</literal>,
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
183 то для доступа используется <literal>stream.foo</literal>.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
184 </para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
185
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
186 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
187 Директив <literal>js_import</literal> может быть несколько.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
188 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
189
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
190 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
191
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
192
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
193 <directive name="js_include">
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
194 <syntax><value>файл</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
195 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
196 <context>stream</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
197
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
198 <para>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
199 Задаёт файл, который позволяет задавать обработчики server и переменных на njs:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
200 <example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
201 nginx.conf:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
202 js_include stream.js;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
203 js_set $js_addr address;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
204 server {
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
205 listen 127.0.0.1:12345;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
206 return $js_addr;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
207 }
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
208
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
209 stream.js:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
210 function address(s) {
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
211 return s.remoteAddress;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
212 }
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
213 </example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
214 </para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
215
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
216 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
217 Директива устарела начиная с
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
218 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>,
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
219 вместо неё следует использовать директиву <link id="js_import"/>.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
220 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
221
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
222 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
223
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
224
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
225 <directive name="js_preread">
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
226 <syntax><value>функция</value> | <value>модуль.функция</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
227 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
228 <context>stream</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
229 <context>server</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
230
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
231 <para>
2128
59a3cc84f507 Renamed nginScript to njs
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2026
diff changeset
232 Задаёт функцию njs, которая будет вызываться в
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
233 <link doc="stream_processing.xml" id="preread_phase">preread</link>-фазе.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
234 Начиная с <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
235 можно ссылаться на функцию модуля.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
236 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
237
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
238 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
239
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
240
2352
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
241 <directive name="js_path">
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
242 <syntax>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
243 <value>путь</value></syntax>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
244 <default/>
2591
f27cedd43e0f Corrected syntax of js_path in stream.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2534
diff changeset
245 <context>stream</context>
2352
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
246 <appeared-in>0.3.0</appeared-in>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
247
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
248 <para>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
249 Задаёт дополнительный путь для модулей njs.
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
250 </para>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
251
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
252 </directive>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
253
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2332
diff changeset
254
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
255 <directive name="js_set">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
256 <syntax>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
257 <value>$переменная</value> <value>функция</value> |
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
258 <value>модуль.функция</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
259 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
260 <context>stream</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
261
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
262 <para>
2128
59a3cc84f507 Renamed nginScript to njs
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2026
diff changeset
263 Задаёт функцию njs для указанной переменной.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
264 Начиная с <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
265 можно ссылаться на функцию модуля.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
266 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
267
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
268 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
269
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
270 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
271
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
272
1843
3492eb9b8138 Translated http and stream js modules into Russian.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
273 <section id="properties" name="Свойства объекта сессии">
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
274
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
275 <para>
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2135
diff changeset
276 Каждый stream-обработчик njs получает один аргумент,
2288
786e96c52c7a Corrected links and example in Russian http and stream js modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
277 <link doc="../njs/reference.xml" id="stream">объект</link> stream-сессии.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
278 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
279
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
280 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
281
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
282 </module>