njs: fetch response a object with undefined values
I think I got an update from the build with docker. In any case, fetch no longer works properly, which worked great before! (this annoys me a bit, since I can’t get any further in my project).
Here is part of my code from my project: https://github.com/stefanwerfling/flyingfish
Nginx config:
server {
listen 80;
listen [::]:80;
set $ff_address_access_url https://127.0.0.1:3000/njs/address_access;
set $ff_listen_id 2;
js_access njs.accessAddressStream;
ssl_preread on;
proxy_pass $ffstream80;
}
/**
* accessAddressStream
* @param s
*/
async function accessAddressStream(s: NginxStreamRequest) {
const v = s.variables;
let address = v.realip_remote_addr;
if (!address) {
address = s.remoteAddress;
}
if (v.ff_address_access_url) {
const reply = await addressCheck(
v.ff_address_access_url,
s,
'stream'
);
if (reply) {
s.warn("accessAddressStream(" + address + ") -> Allow");
s.allow();
return;
}
} else {
s.warn("accessAddressStream() -> url address access not found!");
}
s.warn("accessAddressStream(" + address + ") -> Deny");
s.deny();
}
/**
* addressCheck
* @param url
* @param s
* @param type
*/
async function addressCheck(url: string, s: NginxStreamRequest|NginxHTTPRequest, type: string): Promise<boolean> {
// @ts-ignore
try {
const v = s.variables;
let listen_id = '0';
if (v.ff_listen_id) {
listen_id = v.ff_listen_id;
}
s.warn(`addressCheck(fetch) -> listenId: ${listen_id}, type: ${type} -> ${url}`);
const reply = await ngx.fetch(url, {
method: 'GET',
headers: {
'Accept-Encoding' : '',
'realip_remote_addr': v.realip_remote_addr,
'remote_addr': s.remoteAddress,
'type': type,
'listen_id': listen_id
},
verify: false
});
if (reply) {
s.warn(`addressCheck(fetch->status) -> ${reply.status}`);
if (reply.status === undefined) {
s.error(`addressCheck(fetch->status undefined) ok?: ${reply.ok}!`);
if (reply.ok) {
return true;
}
} else {
if (reply.status == 200) {
return true;
}
}
} else {
s.error(`addressCheck(fetch->reply) is empty!`);
}
} catch (e: any) {
s.warn(`addressCheck(error) -> ${e.message}`);
}
return false;
}
In the logs you can see that the status is now always ‘undefined’. It is important to ensure that the request arrives correctly at nodejs express and that everything is processed.
flyingfish_service | {"level":"silly","message":"HowIsMyPublicIpService::determined: Public ip has not change: 93.196.190.175"}
flyingfish_service | {"level":"info","message":"Port mapping create 192.168.68.1:53 -> 192.168.68.115:5333"}
flyingfish_service | {"level":"info","message":"Port mapping create 192.168.68.1:443 -> 192.168.68.115:443"}
flyingfish_service | {"level":"info","message":"Port mapping create 192.168.68.1:80 -> 192.168.68.115:80"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:01 [warn] 24#24: *17 js: addressCheck(fetch) -> listenId: 2, type: stream -> https://127.0.0.1:3000/njs/address_access"}
flyingfish_service | {"level":"info","message":"AddressAccess::access: realip_remote_addr: 188.166.147.31 remote_addr: 188.166.147.31 type: stream"}
flyingfish_service | {"level":"silly","message":"AddressAccess::access: Listen address check is enable ..."}
flyingfish_service | {"level":"info","message":"AddressAccess::access: Address(188.166.147.31) not found in blacklist."}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 24#24: *17 js: addressCheck(fetch->status) -> undefined"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [error] 24#24: *17 js: addressCheck(fetch->status undefined) ok?: undefined!"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 24#24: *17 js: accessAddressStream(188.166.147.31) -> Deny"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 22#22: *19 js: addressCheck(fetch) -> listenId: 2, type: stream -> https://127.0.0.1:3000/njs/address_access"}
flyingfish_service | {"level":"info","message":"AddressAccess::access: realip_remote_addr: 188.166.147.31 remote_addr: 188.166.147.31 type: stream"}
flyingfish_service | {"level":"silly","message":"AddressAccess::access: Listen address check is enable ..."}
flyingfish_service | {"level":"info","message":"AddressAccess::access: Address(188.166.147.31) not found in blacklist."}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 22#22: *19 js: addressCheck(fetch->status) -> undefined"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [error] 22#22: *19 js: addressCheck(fetch->status undefined) ok?: undefined!"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 22#22: *19 js: accessAddressStream(188.166.147.31) -> Deny"}
flyingfish_service | {"level":"error","message":"NginxServer::stderr: 2022/10/24 21:14:02 [warn] 21#21: *21 js: addressCheck(fetch) -> listenId: 2, type: stream -> https://127.0.0.1:3000/njs/address_access"}
I have now installed the following version:
nginx version: nginx/1.22.1
built by gcc 11.2.1 20220219 (Alpine 11.2.1_git20220219)
built with OpenSSL 1.1.1o 3 May 2022 (running with OpenSSL 1.1.1q 5 Jul 2022)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-perl_modules_path=/usr/lib/perl5/vendor_perl --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common
apk info njs
njs-0.7.5-r0 description:
njs scripting language CLI utility
njs-0.7.5-r0 webpage:
https://nginx.org/en/docs/njs/
njs-0.7.5-r0 installed size:
720 KiB
Why is this suddenly like this?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 31 (16 by maintainers)
Hi @xeioex
I thank you for the fast patch! The collaboration was very interesting.