<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On 23 Jun 2016, at 13:58, Jorge L. <<a href="mailto:jlorgal@gmail.com">jlorgal@gmail.com</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">I've continued with my attempt to integrate my routing logic as javascript code.<div><br></div><div>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:</div><div>  for (var i = 0; i < elements.length; i++) {...}</div><div>but the following one works:</div><div>  for (i = 0; i < elements.length; i++) {…}<br></div></div></blockquote><div><br></div>Yes, var declaration inside for is not currently supported, it will be fixed soon.</div><div><br><blockquote type="cite"><div dir="ltr"><div>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:</div><div><br></div><div>2016/06/23 11:48:42 [emerg] 5390#5390: too long parameter, probably missing terminating """ character in /etc/nginx/js/routing.js:1<br></div><div><br></div><div>Is there any solution for this problem?</div></div></blockquote><div><br></div><div>Currently no. The string parameter length is limited by 4K. We are going to support js in files.</div><br><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 22, 2016 at 8:35 PM, Jorge L. <span dir="ltr"><<a href="mailto:jlorgal@gmail.com" target="_blank">jlorgal@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr"><span style="font-size:12.8px">I'm trying to implement a routing logic with nginScript. I haven't been successful because I miss important javascript feature.</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I would like to give you my feedback just in case it may help to improve njs (from more important/blocking to less important):<br><div><br></div><div><ul><li style="margin-left:15px">There is no way to iterate through the keys of an object. It is not supported none of the following methods:</li><ul><li style="margin-left:15px">Object.keys</li><li style="margin-left:15px">Object.getOwnPropertyNames()<br></li><li style="margin-left:15px">for ... in</li></ul><li style="margin-left:15px">I would like to use/import nginx variables. Something like <a href="http://mailman.nginx.org/pipermail/nginx-devel/2016-May/008207.html" target="_blank">http://mailman.nginx.org/pipermail/nginx-devel/2016-May/008207.html</a> would be great.</li></ul></div></div></div></blockquote></div></div></blockquote><div>We consider another interface: req.variables object.</div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr"><div style="font-size:12.8px"><div><ul><li style="margin-left:15px">I miss string.split function. Probably map, reduce, and many other methods as well.</li><li style="margin-left:15px">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).</li><li style="margin-left:15px">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).<br></li><li style="margin-left:15px">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).</li></ul></div></div></div></blockquote></div></div></blockquote><div><div>We consider another interface: req.cookies object.</div></div><blockquote type="cite"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;"><div dir="ltr"><div style="font-size:12.8px"><div><ul><li style="margin-left:15px">Logging function would be nice to help debugging.</li></ul></div></div><div style="font-size:12.8px">Hope it can be helpful</div></div>
</blockquote></div></div></blockquote></div><div><br></div>Thank you for your feedback!<div>The full String object support, global objects, logging, and files are on the way.<br><div><div><br><div apple-content-edited="true"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br>-- <br>Igor Sysoev<br><a href="http://nginx.com">http://nginx.com</a></div></div></div>
</div>
<br></div></div></div></body></html>