comparison xml/en/docs/http/ngx_http_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_http_js_module" 9 <module name="Module ngx_http_js_module"
10 link="/en/docs/http/ngx_http_js_module.html" 10 link="/en/docs/http/ngx_http_js_module.html"
11 lang="en" 11 lang="en"
12 rev="19"> 12 rev="20">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 The <literal>ngx_http_js_module</literal> module is used to implement 17 The <literal>ngx_http_js_module</literal> module is used to implement
30 30
31 31
32 <section id="example" name="Example Configuration"> 32 <section id="example" name="Example Configuration">
33 33
34 <para> 34 <para>
35 The example works since
36 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>.
35 <example> 37 <example>
36 load_module modules/ngx_http_js_module.so; 38 load_module modules/ngx_http_js_module.so;
37 ... 39 ...
38 40
39 http { 41 http {
40 js_include http.js; 42 js_import http.js;
41 43
42 js_set $foo foo; 44 js_set $foo http.foo;
43 js_set $summary summary; 45 js_set $summary http.summary;
44 46
45 server { 47 server {
46 listen 8000; 48 listen 8000;
47 49
48 location / { 50 location / {
49 add_header X-Foo $foo; 51 add_header X-Foo $foo;
50 js_content baz; 52 js_content http.baz;
51 } 53 }
52 54
53 location = /summary { 55 location = /summary {
54 return 200 $summary; 56 return 200 $summary;
55 } 57 }
56 58
57 location = /hello { 59 location = /hello {
58 js_content hello; 60 js_content http.hello;
59 } 61 }
60 } 62 }
61 } 63 }
62 </example> 64 </example>
63 </para> 65 </para>
108 } 110 }
109 111
110 function hello(r) { 112 function hello(r) {
111 r.return(200, "Hello world!"); 113 r.return(200, "Hello world!");
112 } 114 }
115
116 export default {foo, summary, baz, hello};
113 </example> 117 </example>
114 </para> 118 </para>
115 119
116 </section> 120 </section>
117 121
118 122
119 <section id="directives" name="Directives"> 123 <section id="directives" name="Directives">
120 124
121 <directive name="js_content"> 125 <directive name="js_content">
122 <syntax><value>function</value></syntax> 126 <syntax><value>function</value> | <value>module.function</value></syntax>
123 <default/> 127 <default/>
124 <context>location</context> 128 <context>location</context>
125 <context>limit_except</context> 129 <context>limit_except</context>
126 130
127 <para> 131 <para>
128 Sets an njs function as a location content handler. 132 Sets an njs function as a location content handler.
133 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>,
134 a module function can be referenced.
135 </para>
136
137 </directive>
138
139
140 <directive name="js_import">
141 <syntax><value>module.js</value> |
142 <value>export_name from module.js</value></syntax>
143 <default/>
144 <context>http</context>
145 <appeared-in>0.4.0</appeared-in>
146
147 <para>
148 Imports a module that implements location and variable handlers in njs.
149 The <literal>export_name</literal> is used as a namespace
150 to access module functions.
151 If the <literal>export_name</literal> is not specified,
152 the module name will be used as a namespace.
153 <example>
154 js_import http.js;
155 </example>
156 Here, the module name <literal>http</literal> is used as a namespace
157 while accessing exports.
158 If the imported module contains <literal>foo()</literal>,
159 <literal>http.foo</literal> is used to refer to it.
160 </para>
161
162 <para>
163 Several <literal>js_import</literal> directives can be specified.
129 </para> 164 </para>
130 165
131 </directive> 166 </directive>
132 167
133 168
135 <syntax><value>file</value></syntax> 170 <syntax><value>file</value></syntax>
136 <default/> 171 <default/>
137 <context>http</context> 172 <context>http</context>
138 173
139 <para> 174 <para>
140 Specifies a file that implements location and variable handlers in njs. 175 Specifies a file that implements location and variable handlers in njs:
176 <example>
177 nginx.conf:
178 js_include http.js;
179 location /version {
180 js_content version;
181 }
182
183 http.js:
184 function version(r) {
185 r.return(200, njs.version);
186 }
187 </example>
188 </para>
189
190 <para>
191 The directive is deprecated since
192 <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>,
193 the <link id="js_import"/> directive should be used instead.
141 </para> 194 </para>
142 195
143 </directive> 196 </directive>
144 197
145 198
157 </directive> 210 </directive>
158 211
159 212
160 <directive name="js_set"> 213 <directive name="js_set">
161 <syntax> 214 <syntax>
162 <value>$variable</value> <value>function</value></syntax> 215 <value>$variable</value> <value>function</value> |
216 <value>module.function</value></syntax>
163 <default/> 217 <default/>
164 <context>http</context> 218 <context>http</context>
165 219
166 <para> 220 <para>
167 Sets an njs function for the specified variable. 221 Sets an njs function for the specified variable.
222 Since <link doc="../njs/changes.xml" id="njs0.4.0">0.4.0</link>,
223 a module function can be referenced.
168 </para> 224 </para>
169 225
170 </directive> 226 </directive>
171 227
172 </section> 228 </section>