nginScript (njs) feedback

Jorge L. jlorgal at gmail.com
Thu Jun 23 10:58:39 UTC 2016


I've continued with my attempt to integrate my routing logic as javascript
code.

Regarding my previous feedback, it is possible to iterate the keys of an
object with "for ... in". However, you cannot use "var" keyword to assign
the result of the loop. For example, the following code fails:
  for (var i = 0; i < elements.length; i++) {...}
but the following one works:
  for (i = 0; i < elements.length; i++) {...}

I've found a blocking point. There is a limitation of the size of the
script. It could be solved easily if I could import other nginx vars. My
module currently has 4202 chars (or 123 lines). This is really strange
because I don't consider it to be too big. The error raised is:

2016/06/23 11:48:42 [emerg] 5390#5390: too long parameter, probably missing
terminating """ character in /etc/nginx/js/routing.js:1

Is there any solution for this problem?

On Wed, Jun 22, 2016 at 8:35 PM, Jorge L. <jlorgal at gmail.com> wrote:

> 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
>    http://mailman.nginx.org/pipermail/nginx-devel/2016-May/008207.html 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20160623/52e071e1/attachment.html>


More information about the nginx mailing list