Open jimbo8098 opened 3 years ago
Through my tests today, I've tried:
() => {}
arrow functions to normal function function() {}
with no effect.console.log("server",location)
within the locations.forEach block. This shows the location objects. As an example, one was { location: '~* /.*.php$', deny_addresses: [ 'all' ] }
, i.e. what I expectedconsole.log("location",access_log)
within the location,ejs file which showed an access_log object, this is unexpected. The result was location { location: '/dev/null1', format: null }
, i.e. the one which should be in the server block.It would seem my hunch was right, that this is scope related, but I'm not sure exactly why. I only need access to the variables passed to the view from the include function, I don't need the locals passed to the render function. Is there a way I can even enforce that?
Hi folks,
I've already posted this on StackOverflow but I figured I'd post it here since it doesn't seem there's anything related.
I have made a templater for Nginx configurations within Nodejs which uses EJS to template the configurations. Here is a simplified version of the code I'm using to generate the config:
And here's the site.conf.js file:
server.conf.ejs
And finally log.ejs
The output here is:
Now what's confusing me is how the console.log output for
data.servers[0].locations
shows there is noaccess_log
definition yet it is within the output configuration file. The value used is the one fromdata.servers[0]
instead. I assume this is scope related since theaccess_log
property has the same name in each case. I have tried using arrow functions(el) => {}
and old-stylefunction(el) {}
to attempt to rule out scopes through that with no desirable effect and I've tried excludingObject.assign
and replacing it with an anonymous object defined like:instead. This resulted in the same so I think the scope is the problem here.
When I assign a value to access_log within location that overrides the value provided by the server block and works as expected but I shouldn't need to do that.
Our end goal is to output the formatted nginx config like so:
Any ideas where I'm going wrong here?