Mercurial > hg > nginx-site
changeset 2556:c81b1fadbcf3
Updated hello_world example in njs.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Fri, 19 Jun 2020 12:48:01 +0100 |
parents | 5b2764724e0d |
children | 7c020a4ef753 |
files | xml/en/docs/njs/examples.xml xml/en/docs/njs/index.xml xml/ru/docs/njs/examples.xml xml/ru/docs/njs/index.xml |
diffstat | 4 files changed, 34 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/xml/en/docs/njs/examples.xml +++ b/xml/en/docs/njs/examples.xml @@ -9,7 +9,7 @@ <article name="Examples" link="/en/docs/njs/examples.html" lang="en" - rev="14"> + rev="15"> <section id="summary"> @@ -30,9 +30,15 @@ events {} http { js_import http.js; - js_content http.hello; + + server { + listen 8000; + + location / { + js_content http.hello; + } + } } - </example> </para>
--- a/xml/en/docs/njs/index.xml +++ b/xml/en/docs/njs/index.xml @@ -9,7 +9,7 @@ <article name="njs scripting language" link="/en/docs/njs/index.html" lang="en" - rev="30" + rev="31" toc="no"> <section id="summary"> @@ -138,13 +138,15 @@ To use njs in nginx: <listitem id="hello_world"> <para> -create an njs script file, for example, <path>hello_world.js</path>. +create an njs script file, for example, <path>http.js</path>. See <link doc="reference.xml">Reference</link> for the list of njs properties and methods. <example> function hello(r) { r.return(200, "Hello world!"); } + +export default {hello}; </example> </para> </listitem> @@ -155,26 +157,25 @@ function hello(r) { in the <path>nginx.conf</path> file, enable <link doc="../http/ngx_http_js_module.xml">ngx_http_js_module</link> module and specify the -<link doc="../http/ngx_http_js_module.xml" id="js_include">js_include</link> +<link doc="../http/ngx_http_js_module.xml" id="js_import">js_import</link> directive -with the <path>hello_world.js</path> script file: +with the <path>http.js</path> script file: <example> load_module modules/ngx_http_js_module.so; events {} http { - js_include hello_world.js; + js_import http.js; server { listen 8000; location / { - js_content hello; + js_content http.hello; } } } - </example> </para> </listitem>
--- a/xml/ru/docs/njs/examples.xml +++ b/xml/ru/docs/njs/examples.xml @@ -9,7 +9,7 @@ <article name="Примеры использования" link="/ru/docs/njs/examples.html" lang="ru" - rev="14"> + rev="15"> <section id="summary"> @@ -29,9 +29,15 @@ events {} http { js_import http.js; - js_content http.hello; + + server { + listen 8000; + + location / { + js_content http.hello; + } + } } - </example> </para>
--- a/xml/ru/docs/njs/index.xml +++ b/xml/ru/docs/njs/index.xml @@ -9,7 +9,7 @@ <article name="Сценарный язык njs" link="/ru/docs/njs/index.html" lang="ru" - rev="30" + rev="31" toc="no"> <section id="summary"> @@ -139,13 +139,15 @@ ngx_stream_js_module</link> <listitem id="hello_world"> <para> -создать файл сценария njs, например <path>hello_world.js</path>. +создать файл сценария njs, например <path>http.js</path>. Описание свойств и методов языка njs см. в <link doc="reference.xml">справочнике</link>. <example> function hello(r) { r.return(200, "Hello world!"); } + +export default {hello}; </example> </para> </listitem> @@ -156,25 +158,24 @@ function hello(r) { в файле <path>nginx.conf</path> включить модуль <link doc="../http/ngx_http_js_module.xml">ngx_http_js_module</link> и указать директиву -<link doc="../http/ngx_http_js_module.xml" id="js_include">js_include</link> -с файлом сценария <path>hello_world.js</path>: +<link doc="../http/ngx_http_js_module.xml" id="js_import">js_import</link> +с файлом сценария <path>http.js</path>: <example> load_module modules/ngx_http_js_module.so; events {} http { - js_include hello_world.js; + js_import http.js; server { listen 8000; location / { - js_content hello; + js_content http.hello; } } } - </example> </para> </listitem>