Support inline lua block
machados opened this issue · 3 comments
Do you have any plans do add support for inline lua blocks?
At the moment (nginx-conf 1.2.0) lua blocks are being removed from the output (https://github.com/openresty/lua-nginx-module#readme).
It would be nice to handle those blocks just as a big string.
I didn't even know I didn't support those. I'll look into it this weekend.
I know very little about the Lua integration. How would you recommend we support this? Is it just anything that ends in by_lua_block
should not be parsed and fed verbatim through the generator?
That would be great and you are exactly right, just be aware that inside the block there might be {
}
characters.
This is supported and published to npm in 1.3.0
. Take a look at the tests in 46becb0 for a better overview, but here's a brief synopsis:
file.nginx.http.server.location._addVerbatimBlock('rewrite_by_lua_block', 'ngx.say("hello world")');
console.log(file.toString());
/*
http {
server {
location {
rewrite_by_lua_block { ngx.say("hello world") }
}
*/
One (important) caveat is that curly brackets in a Lua comment or string CANNOT be mismatched, or this module will throw an error. So, this is bad:
content_by_lua_block {
-- this is a comment with a mismatched }
}
and so is this:
content_by_lua_block {
ngx.say("mismatched }")
}
but this is fine:
content_by_lua_block {
-- this is a comment with a matching {}
}
I don't really know a good way to solve that without actually parsing Lua code, which is something I'd really rather not do in this module.
I've never actually used the Lua integration feature in nginx, so let me know if I missed something, or it doesn't work as expected.