Kong - Lua debugging?

Hi, I’ve been looking at using Kong in one of my projects but I would like to understand how to debug the Lua code that gets executed in the configuration blocks from the ngnix/openresty configuration with a LUA IDE so I can step in and out of functions etc etc…

I could insert print statments and ngx.log(ngx.STDERR,"xxx") within the code but this makes debugging a pain. Is it possible to connect to kong remotely and debug the lua code written in the configuration file via an IDE?

I know there is ZeroBrane and IntelliJ+EmmyLua as well as VSCode with the lua plugins.

I know there is something called Mobdebug which should start a debugging server if I understand correctly.

luarocks install mobdebug

I am using Kong via a docker image and setting the following KONG_NGINX_HTTP_INCLUDE with contents of the configuration file shown below.

For example: If I have an extra configuration file which looks like this where lua code is written directly in the access_by_lua_*. I would like to if possible set a debugger and breakpoints in the access_by_lua block.

lua_code_cache off;

server {
  listen 8000;
  server_name localhost;

  access_log /dev/stdout;
  error_log /dev/stderr;

  location /rest {
    access_by_lua_block {
    local inspect = require("inspect")
    local squares = {1, 4, 9}
    inspect(squares)
    ngx.say("Hello,  testing !")
    }
    
}

Perhaps I have to extract the code in the access_by_lua_block and put it in its own lua file and then include it?

lua_code_cache off;

server {
  listen 8000;
  server_name localhost;

  access_log /dev/stdout;
  error_log /dev/stderr;

  location /rest {
    access_by_lua_block {
     content_by_lua_file 'lua/main.lua'
    }
    
}

Any help is appreciated :smiley:


© 2018 Kong Inc.    Terms  •  Privacy  •  FAQ