I’m trying to implement a routing logic with nginScript. I haven’t been
successful because I miss important javascript feature.
I would like to give you my feedback just in case it may help to improve
njs (from more important/blocking to less important):
- There is no way to iterate through the keys of an object. It is not
supported none of the following methods:- Object.keys
- Object.getOwnPropertyNames()
- for … in
- I would like to use/import nginx variables. Something like
[njs] Allow access to nginx vars via the njs $v variable
would
be great. - I miss string.split function. Probably map, reduce, and many other
methods as well. - It would be nice to have some “singleton” support where I could set
a
variable that is evaluated only once (first time is required or when
nginx
is started/reloaded). It’s clear that it should not be related to
request/response but this approach would improve performance by
avoiding
executing same thing for each request. It would be similar to
importing a
javascript module (it’s only imported once and global vars and
requirements
are satisfied only once). - I would like to include javascript modules. I’m using a directive:
“include /etc/nginx/js/*.js;” but this .js files need to include the
js_set
$xxx “…” which makes the file to be invalid javascript (and you may
miss
some features from your javascript IDE). - It would be nice to access a cookie by name (it wouldn’t be
necessary
if I could access to a nginx var like $v.cookie_XXX). - Logging function would be nice to help debugging.
Hope it can be helpful