annotate 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
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
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
9 <module name="Module ngx_http_js_module"
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
10 link="/en/docs/http/ngx_http_js_module.html"
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
11 lang="en"
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
12 rev="20">
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>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
17 The <literal>ngx_http_js_module</literal> module is used to implement
1844
f56626ce9c40 Changed JavaScript to nginScript.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
18 location and variable handlers
2245
87a0e2c73a25 Refactored njs documentation.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2244
diff changeset
19 in <link doc="../njs/index.xml">njs</link> —
1844
f56626ce9c40 Changed JavaScript to nginScript.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1840
diff changeset
20 a subset of the JavaScript language.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
21 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
22
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
23 <para>
2188
523dc4cc8745 Updated installation procedure in njs modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2187
diff changeset
24 This module is not built by default.
523dc4cc8745 Updated installation procedure in njs modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2187
diff changeset
25 Download and install instructions are available
2245
87a0e2c73a25 Refactored njs documentation.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2244
diff changeset
26 <link doc="../njs/install.xml">here</link>.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
27 </para>
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 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
30
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 <section id="example" name="Example Configuration">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
33
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
34 <para>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
35 The example works since
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
36 <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
37 <example>
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
38 load_module modules/ngx_http_js_module.so;
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
39 ...
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
40
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
41 http {
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
42 js_import http.js;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
43
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
44 js_set $foo http.foo;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
45 js_set $summary http.summary;
1858
36cbfff92c6d Restricted context of js_set directive to http and stream only.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 1853
diff changeset
46
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
47 server {
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
48 listen 8000;
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
49
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
50 location / {
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
51 add_header X-Foo $foo;
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
52 js_content http.baz;
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
53 }
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
54
2206
5cacd6fffade Eliminated some examples of unsafe prefix locations.
Ruslan Ermilov <ru@nginx.com>
parents: 2190
diff changeset
55 location = /summary {
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
56 return 200 $summary;
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
57 }
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
58
2206
5cacd6fffade Eliminated some examples of unsafe prefix locations.
Ruslan Ermilov <ru@nginx.com>
parents: 2190
diff changeset
59 location = /hello {
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
60 js_content http.hello;
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
61 }
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
62 }
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 </example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
65 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
66
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 The <path>http.js</path> file:
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
69 <example>
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
70 function foo(r) {
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
71 r.log("hello from foo() handler");
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
72 return "foo";
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
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
75 function summary(r) {
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
76 var a, s, h;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
77
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
78 s = "JS summary\n\n";
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
79
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
80 s += "Method: " + r.method + "\n";
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
81 s += "HTTP version: " + r.httpVersion + "\n";
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
82 s += "Host: " + r.headersIn.host + "\n";
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
83 s += "Remote Address: " + r.remoteAddress + "\n";
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
84 s += "URI: " + r.uri + "\n";
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
85
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
86 s += "Headers:\n";
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
87 for (h in r.headersIn) {
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
88 s += " header '" + h + "' is '" + r.headersIn[h] + "'\n";
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
89 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
90
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
91 s += "Args:\n";
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
92 for (a in r.args) {
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
93 s += " arg '" + a + "' is '" + r.args[a] + "'\n";
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
94 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
95
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
96 return s;
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
97 }
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
98
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
99 function baz(r) {
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
100 r.status = 200;
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
101 r.headersOut.foo = 1234;
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
102 r.headersOut['Content-Type'] = "text/plain; charset=utf-8";
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
103 r.headersOut['Content-Length'] = 15;
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
104 r.sendHeader();
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
105 r.send("nginx");
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
106 r.send("java");
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
107 r.send("script");
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
108
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
109 r.finish();
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
110 }
2190
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
111
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
112 function hello(r) {
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
113 r.return(200, "Hello world!");
dfc49994218c Updated example in HTTP njs module.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2188
diff changeset
114 }
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
115
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
116 export default {foo, summary, baz, hello};
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
117 </example>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
118 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
119
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
120 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
121
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
122
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
123 <section id="directives" name="Directives">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
124
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
125 <directive name="js_content">
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
126 <syntax><value>function</value> | <value>module.function</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
127 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
128 <context>location</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
129 <context>limit_except</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
130
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
131 <para>
2128
59a3cc84f507 Renamed nginScript to njs
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2026
diff changeset
132 Sets an njs function as a location content handler.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
133 Since <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
134 a module function can be referenced.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
135 </para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
136
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
137 </directive>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
138
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
139
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
140 <directive name="js_import">
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
141 <syntax><value>module.js</value> |
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
142 <value>export_name from module.js</value></syntax>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
143 <default/>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
144 <context>http</context>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
145 <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
146
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
147 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
148 Imports a module that implements location and variable handlers in njs.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
149 The <literal>export_name</literal> is used as a namespace
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
150 to access module functions.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
151 If the <literal>export_name</literal> is not specified,
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
152 the module name will be used as a namespace.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
153 <example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
154 js_import http.js;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
155 </example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
156 Here, the module name <literal>http</literal> is used as a namespace
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
157 while accessing exports.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
158 If the imported module contains <literal>foo()</literal>,
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
159 <literal>http.foo</literal> is used to refer to it.
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
160 </para>
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 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
163 Several <literal>js_import</literal> directives can be specified.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
164 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
165
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
166 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
167
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
168
2142
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
169 <directive name="js_include">
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
170 <syntax><value>file</value></syntax>
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
171 <default/>
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
172 <context>http</context>
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
173
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
174 <para>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
175 Specifies a file that implements location and variable handlers in njs:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
176 <example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
177 nginx.conf:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
178 js_include http.js;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
179 location /version {
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
180 js_content version;
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
181 }
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
182
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
183 http.js:
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
184 function version(r) {
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
185 r.return(200, njs.version);
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
186 }
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
187 </example>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
188 </para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
189
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
190 <para>
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
191 The directive is deprecated since
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
192 <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
193 the <link id="js_import"/> directive should be used instead.
2142
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
194 </para>
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
195
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
196 </directive>
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
197
ca7568f67dee Sorted directives alphabetically.
Ruslan Ermilov <ru@nginx.com>
parents: 2135
diff changeset
198
2352
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
199 <directive name="js_path">
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
200 <syntax>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
201 <value>path</value></syntax>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
202 <default/>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
203 <context>http</context>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
204 <appeared-in>0.3.0</appeared-in>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
205
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
206 <para>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
207 Sets an additional path for njs modules.
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
208 </para>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
209
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
210 </directive>
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
211
1101e24c6d14 Documented the js_path directive.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
212
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
213 <directive name="js_set">
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
214 <syntax>
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
215 <value>$variable</value> <value>function</value> |
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
216 <value>module.function</value></syntax>
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
217 <default/>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
218 <context>http</context>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
219
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
220 <para>
2128
59a3cc84f507 Renamed nginScript to njs
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2026
diff changeset
221 Sets an njs function for the specified variable.
2530
407c5bd5bffc Documented the js_import directive and corresponding changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2352
diff changeset
222 Since <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
223 a module function can be referenced.
1840
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
224 </para>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
225
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
226 </directive>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
227
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
228 </section>
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
229
15632fc2d548 Documented http and stream nginScript modules.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
230
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
231 <section id="arguments" name="Request Argument">
2149
6df1a86a60b8 Added new njs HTTP properties and methods.
Roman Arutyunyan <arut@nginx.com>
parents: 2142
diff changeset
232
6df1a86a60b8 Added new njs HTTP properties and methods.
Roman Arutyunyan <arut@nginx.com>
parents: 2142
diff changeset
233 <para>
2187
ed905ab118c7 Updated HTTP njs module according to njs 0.2.2.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
234 Each HTTP njs handler receives one argument, a request
2246
32ba43abf9cd Renamed njs API, njs Changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2245
diff changeset
235 <link doc="../njs/reference.xml" id="http">object</link>.
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 </section>
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 </module>