Hello!
On Sun, May 10, 2015 at 11:46 PM, <cga...@gmail.com> wrote:
> I want to use lua-resty-mysql to provide content to my web app. My plan is
> to query the database and based on the results substitute text from the
> default HTML served by Nginx. I've read the documentation and tutorials but
> I'm a bit confused which handler should be used in this case. I've tried
> access_by_lua and rewrite_by_lua but ngx.say() always overwrites the default
> HTML output. How can I query the database and only overwrite a portion of
> the default HTML?
>
If your database query does not depend on the actual response body
data, then you can query the db via lua-resty-mysql in access_by_lua
or rewrite_by_lua, and then save the results (or substibution rules)
into the magic ngx.ctx table. At the same time, you do the actual
substitution in your body_filter_by_lua handler by reading the "rules"
in ngx.ctx. But be careful about response body's data chunk
boundaries. See the official documentation for the body_filter_by_lua
feature.
Just my 2 cents.
Best regards,
-agentzh
P.S. Sorry for my late reply; I've been on vacation lately.