Mercurial > hg > nginx-site
comparison xml/en/docs/stream/ngx_stream_js_module.xml @ 2530:407c5bd5bffc
Documented the js_import directive and corresponding changes.
Also the following changes:
- js_include is deprecated
- js_access, js_content, js_filter, js_preread, js_set
can now accept module.function
- Example Configuration changed for both http and stream js modules.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Wed, 22 Apr 2020 16:54:11 +0100 |
parents | 1101e24c6d14 |
children | 617bc29bd759 |
comparison
equal
deleted
inserted
replaced
2529:8cc141e0460f | 2530:407c5bd5bffc |
---|---|
7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> | 7 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> |
8 | 8 |
9 <module name="Module ngx_stream_js_module" | 9 <module name="Module ngx_stream_js_module" |
10 link="/en/docs/stream/ngx_stream_js_module.html" | 10 link="/en/docs/stream/ngx_stream_js_module.html" |
11 lang="en" | 11 lang="en" |
12 rev="17"> | 12 rev="18"> |
13 | 13 |
14 <section id="summary"> | 14 <section id="summary"> |
15 | 15 |
16 <para> | 16 <para> |
17 The <literal>ngx_stream_js_module</literal> module is used to implement | 17 The <literal>ngx_stream_js_module</literal> module is used to implement |
29 | 29 |
30 | 30 |
31 <section id="example" name="Example Configuration"> | 31 <section id="example" name="Example Configuration"> |
32 | 32 |
33 <para> | 33 <para> |
34 The example works since | |
35 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>. | |
34 <example> | 36 <example> |
35 load_module modules/ngx_stream_js_module.so; | 37 load_module modules/ngx_stream_js_module.so; |
36 ... | 38 ... |
37 | 39 |
38 stream { | 40 stream { |
39 js_include stream.js; | 41 js_import stream.js; |
40 | 42 |
41 js_set $bar bar; | 43 js_set $bar stream.bar; |
42 js_set $req_line req_line; | 44 js_set $req_line stream.req_line; |
43 | 45 |
44 server { | 46 server { |
45 listen 12345; | 47 listen 12345; |
46 | 48 |
47 js_preread preread; | 49 js_preread stream.preread; |
48 return $req_line; | 50 return $req_line; |
49 } | 51 } |
50 | 52 |
51 server { | 53 server { |
52 listen 12346; | 54 listen 12346; |
53 | 55 |
54 js_access access; | 56 js_access stream.access; |
55 proxy_pass 127.0.0.1:8000; | 57 proxy_pass 127.0.0.1:8000; |
56 js_filter header_inject; | 58 js_filter stream.header_inject; |
57 } | 59 } |
58 } | 60 } |
59 | 61 |
60 http { | 62 http { |
61 server { | 63 server { |
119 return; | 121 return; |
120 } | 122 } |
121 | 123 |
122 s.allow(); | 124 s.allow(); |
123 } | 125 } |
126 | |
127 export default {bar, preread, req_line, access}; | |
124 </example> | 128 </example> |
125 </para> | 129 </para> |
126 | 130 |
127 </section> | 131 </section> |
128 | 132 |
129 | 133 |
130 <section id="directives" name="Directives"> | 134 <section id="directives" name="Directives"> |
131 | 135 |
132 <directive name="js_access"> | 136 <directive name="js_access"> |
133 <syntax><value>function</value></syntax> | 137 <syntax><value>function</value> | <value>module.function</value></syntax> |
134 <default/> | 138 <default/> |
135 <context>stream</context> | 139 <context>stream</context> |
136 <context>server</context> | 140 <context>server</context> |
137 | 141 |
138 <para> | 142 <para> |
139 Sets an njs function which will be called at the | 143 Sets an njs function which will be called at the |
140 <link doc="stream_processing.xml" id="access_phase">access</link> phase. | 144 <link doc="stream_processing.xml" id="access_phase">access</link> phase. |
145 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>, | |
146 a module function can be referenced. | |
141 </para> | 147 </para> |
142 | 148 |
143 </directive> | 149 </directive> |
144 | 150 |
145 | 151 |
146 <directive name="js_filter"> | 152 <directive name="js_filter"> |
147 <syntax><value>function</value></syntax> | 153 <syntax><value>function</value> | <value>module.function</value></syntax> |
148 <default/> | 154 <default/> |
149 <context>stream</context> | 155 <context>stream</context> |
150 <context>server</context> | 156 <context>server</context> |
151 | 157 |
152 <para> | 158 <para> |
153 Sets a data filter. | 159 Sets a data filter. |
160 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>, | |
161 a module function can be referenced. | |
162 </para> | |
163 | |
164 </directive> | |
165 | |
166 | |
167 <directive name="js_import"> | |
168 <syntax><value>module.js</value> | | |
169 <value>export_name from module.js</value></syntax> | |
170 <default/> | |
171 <context>stream</context> | |
172 <appeared-in>0.4.0</appeared-in> | |
173 | |
174 <para> | |
175 Imports a module that implements location and variable handlers in njs. | |
176 The <literal>export_name</literal> is used as a namespace | |
177 to access module functions. | |
178 If the <literal>export_name</literal> is not specified, | |
179 the module name will be used as a namespace. | |
180 <example> | |
181 js_import stream.js; | |
182 </example> | |
183 Here, the module name <literal>stream</literal> is used as a namespace | |
184 while accessing exports. | |
185 If the imported module contains <literal>foo()</literal>, | |
186 <literal>stream.foo</literal> is used to refer to it. | |
187 </para> | |
188 | |
189 <para> | |
190 Several <literal>js_import</literal> directives can be specified. | |
154 </para> | 191 </para> |
155 | 192 |
156 </directive> | 193 </directive> |
157 | 194 |
158 | 195 |
160 <syntax><value>file</value></syntax> | 197 <syntax><value>file</value></syntax> |
161 <default/> | 198 <default/> |
162 <context>stream</context> | 199 <context>stream</context> |
163 | 200 |
164 <para> | 201 <para> |
165 Specifies a file that implements server and variable handlers in njs. | 202 Specifies a file that implements server and variable handlers in njs: |
203 <example> | |
204 nginx.conf: | |
205 js_include stream.js; | |
206 js_set $js_addr address; | |
207 server { | |
208 listen 127.0.0.1:12345; | |
209 return $js_addr; | |
210 } | |
211 | |
212 stream.js: | |
213 function address(s) { | |
214 return s.remoteAddress; | |
215 } | |
216 </example> | |
217 </para> | |
218 | |
219 <para> | |
220 The directive is deprecated since | |
221 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>, | |
222 the <link id="js_import"/> directive should be used instead. | |
166 </para> | 223 </para> |
167 | 224 |
168 </directive> | 225 </directive> |
169 | 226 |
170 | 227 |
181 | 238 |
182 </directive> | 239 </directive> |
183 | 240 |
184 | 241 |
185 <directive name="js_preread"> | 242 <directive name="js_preread"> |
186 <syntax><value>function</value></syntax> | 243 <syntax><value>function</value> | <value>module.function</value></syntax> |
187 <default/> | 244 <default/> |
188 <context>stream</context> | 245 <context>stream</context> |
189 <context>server</context> | 246 <context>server</context> |
190 | 247 |
191 <para> | 248 <para> |
192 Sets an njs function which will be called at the | 249 Sets an njs function which will be called at the |
193 <link doc="stream_processing.xml" id="preread_phase">preread</link> phase. | 250 <link doc="stream_processing.xml" id="preread_phase">preread</link> phase. |
251 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>, | |
252 a module function can be referenced. | |
194 </para> | 253 </para> |
195 | 254 |
196 </directive> | 255 </directive> |
197 | 256 |
198 | 257 |
199 <directive name="js_set"> | 258 <directive name="js_set"> |
200 <syntax> | 259 <syntax> |
201 <value>$variable</value> <value>function</value></syntax> | 260 <value>$variable</value> <value>function</value> | |
261 <value>module.function</value></syntax> | |
202 <default/> | 262 <default/> |
203 <context>stream</context> | 263 <context>stream</context> |
204 | 264 |
205 <para> | 265 <para> |
206 Sets an njs function for the specified variable. | 266 Sets an njs function for the specified variable. |
267 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>, | |
268 a module function can be referenced. | |
207 </para> | 269 </para> |
208 | 270 |
209 </directive> | 271 </directive> |
210 | 272 |
211 </section> | 273 </section> |