Hi,

See the following reply on Github

https://github.com/nginx/njs/issues/460#issuecomment-1015642606

On 06.04.2022 00:02, 王明君 wrote:
Hi, sorry to bother again ~
I was trying to access variables declared using js_var but failed. Confused why is that.

This is a test demo, but actually i have a massive nginx config file that i want to minify using njs, and under which circumstance i need the js script to have access to variables declared in nginx.conf, either by using js_var directive, or something else (not found).

*demo - nginx.conf*
----------------------------------
http {
js_import main from main.js;
js_var $abc "ss fd";

server {

    listen 80;
    server_name localhost;

    location / {

        js_content main.hello;

    }

}
}

*demo - **main.js*
----------------------------------
function hello(r) {
       r.headersOut["Content-Type"] = "application/json";
       var m = {};
       for(var p in r)
               m[p] = r[p];
       m["variables"] = r.variables;
       r.return(200, JSON.stringify(m));
}

export default { hello };
---------------------------------------

*demo - **output*



=======================

*uname -a*
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

*cat os-release*
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/";
BUG_REPORT_URL="https://bugs.centos.org/";

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

        

<https://maas.mail.163.com/dashi-web-extend/html/proSignature.html?ftlId=1&name=%E7%8E%8B%E6%98%8E%E5%90%9B&uid=wmjhappy_ok%40126.com&iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fsm169ab9356098976ee9a1ecee61e677f0.jpg&items=%5B%22wmjhappy_ok%40126.com%22%5D>

_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org

Reply via email to