Learn about Centmin Mod LEMP Stack today
Register Now

Nginx [nginx-announce] njs-0.5.3

Discussion in 'Nginx and PHP-FPM news & discussions' started by eva2000, Mar 31, 2021.

  1. eva2000

    eva2000 Administrator Staff Member

    46,649
    10,590
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,435
    Local Time:
    7:38 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    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

    Continue reading...