openresty / echo-nginx-module

An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file
http://wiki.nginx.org/NginxHttpEchoModule
BSD 2-Clause "Simplified" License
1.17k stars 254 forks source link

output file content #36

Closed gcmartijn closed 10 years ago

gcmartijn commented 10 years ago

I'm testing things and want to know if this is possible ?

 location / {
                content_by_lua '
                local mysql = require "resty.mysql"
                local db, err = mysql:new()
                if not db then
                    ngx.say("failed to instantiate mysql: ", err)
                    return
                end

  here i handle a query and if oke then
    ngx.say(/js/jsfile1.js)
    ngx.say(/js/jsfile2.js)
    ngx.say(/vol/www/lala/js/jsfile3.js)
   ngx.say(/home/bla/js/jsfile3.js)
  end
 '
}

The goal is to output file content after a query check. The content is in this case javascript for the client.

gcmartijn commented 10 years ago

I think I found something.

-- construct the requests table local reqs = {} table.insert(reqs, { "/mysql" }) table.insert(reqs, { "/postgres" }) table.insert(reqs, { "/redis" }) table.insert(reqs, { "/memcached" })

-- issue all the requests at once and wait until they all return
local resps = { ngx.location.capture_multi(reqs) }

-- loop over the responses table
for i, resp in ipairs(resps) do
    -- process the response table "resp"
end

will check this now