Welcome! Log In Create A New Profile

Advanced

Re: Njs - r.variables does not contain variables declared by js_var

All files from this thread

File Name File Size   Posted by Date  
EE79CD01-959B-4103-AC51-0CF482A91F88.png 7.6 KB open | download 王明君 04/06/2022 Read message
Dmitry Volyntsev
April 06, 2022 12:40PM
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-leave@nginx.org
_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-leave@nginx.org
Subject Author Posted

Njs - r.variables does not contain variables declared by js_var Attachments

王明君 April 06, 2022 03:08AM

Re: Njs - r.variables does not contain variables declared by js_var

Dmitry Volyntsev April 06, 2022 12:40PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 306
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready