Welcome! Log In Create A New Profile

Advanced

[nginx-announce] njs-0.5.3

Posted by Dmitry Volyntsev 
Dmitry Volyntsev
[nginx-announce] njs-0.5.3
March 30, 2021 03:32PM
Hello,

I'm glad to announce a new release of NGINX JavaScript module (njs).

This release focuses on extending the modules functionality.

Notable new features:
- js_var directive. The directive creates an nginx variable writable
from njs. The variable is not overwritten after a redirect unlike
variables created with the set directive.

This is especially useful in situations where some directive value
depends on the result of a subrequest.

The following example illustrates the case where Authorization header
is processed by a HTTP endpoint which returns foo value as a result.
This result is passed as a header to the backend.

: nginx.conf:
: js_import main.js;
:
: js_var $foo;
: ..
:
: location /secure/ {
: auth_request /set_foo;
:
: proxy_set_header Foo $foo;
: proxy_pass http://backend;
: }
:
: location =/set_foo {
: internal;
: js_content main.set_foo;
: }
:
: main.js:
: function set_foo(r) {
: ngx.fetch('http://127.0.0.1:8080', {headers: {Authorization: r.headersIn.Authorization}})
: .then(reply => {
: r.variables.foo = reply.headers.get('foo');
: r.return(200);
: });
: }
:
: export default {set_foo};

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs
- Using node modules with njs:
http://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
http://nginx.org/en/docs/njs/typescript.html

Feel free to try it and give us feedback on:

- Github: https://github.com/nginx/njs/issues
- Mailing list: http://mailman.nginx.org/mailman/listinfo/nginx-devel


Changes with njs 0.5.3 30 Mar 2021

nginx modules:

*) Feature: added the "js_var" directive.

_______________________________________________
nginx-announce mailing list
nginx-announce@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-announce
Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 150
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready