[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Simple Xavante direct handler
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Thu, 26 Nov 2009 15:21:39 +0100
2009/11/25 Ignacio Burgueño <ignaciob@inconcertcc.com>:
> Jerome Vuarand wrote:
>> Thanks, I'll give it a look. But afaict this looks like *a lot* of
>> code, for something which is a mere simplification of what Xavante
>> already does.
>
> He! Possibly. I replicated a lot of code because when I started my project
> Xavante was fluctuating a lot, so that gave me better isolation.
>
> But I think you can get away just by copying the two functions
> (makeRawSapiHandler and custom_sapi_loader)
I finally got it to work with not too much code (most of it given by
Ignacio) but some time wasted. Here is the final webserver code of my
application :
local function custom_sapi_loader(wsapi_env)
wsapi.common.normalize_paths(wsapi_env)
_G.CGILUA_ISDIRECT = true
_G.CGILUA_CONF = "."
_G.CGILUA_TMP = "."
local app = require "wsapi.sapi"
local status, headers, iterator = app.run(wsapi_env)
-- it is necessary to reload Cgilua packages and wsapi.sapi. it has
way too much dependency on global
-- environment
package.loaded["cgilua"] = nil
cgilua.SAPI = nil
package.loaded["wsapi.sapi"] = nil
return status, headers, iterator
end
local webdir = ".\\"
xavante.HTTP{
server = {host = "*", port = web_port},
defaultHost = {
rules = {
{
match = "^[^%./]*/$",
with = xavante.redirecthandler,
params = {"index.lp"},
},
{
match = "%.lp$",
with = wsapi.xavante.makeHandler(custom_sapi_loader, nil, webdir, webdir),
},
{
match = ".",
with = xavante.filehandler,
params = {baseDir = webdir}
},
},
},
}
I then run my coroutine-based, copas-like event loop. It would be nice
to add in-interpreter processing of LuaPages to Xavante, or to put an
example like the code above in a very visible place.