pid        /tmp/nginx.pid;
error_log stderr error;
daemon off;

events {
    worker_connections  16384;
}

http {
    resolver 127.0.0.1;
    access_log off;
    lua_package_path '/openresty/?.lua;;';
    init_by_lua_block {
        jit.opt.start("minstitch=10")
        require "resty.core"
        encode = require("cjson").encode
        mysql = require("resty.mysql")
        app = require("app")
    }

    server {
        listen       8080;
        location /plaintext {
            default_type "text/plain";
            content_by_lua_block {
                ngx.print("Hello, world!")
            }
        }

        location /json {
            default_type "application/json";
            content_by_lua_block {
                ngx.print(encode({message = "Hello, World!"}))
            }
        }
        location /fortunes {
            default_type "text/html; charset=UTF-8";
            content_by_lua_block {
                app.fortunes()
            }
        }
        location /db {
            default_type "application/json";
            content_by_lua_block {
                app.db()
            }
        }
        location / {
            default_type "application/json";
            content_by_lua_block {
                app.queries()
            }
        }
    }
}
