I'm forwarding the following message because I think it is relevant here.

Regards,
Ignacio

-------- Original Message --------
Subject: Re: Simple Xavante direct handler
Date: Thu, 26 Nov 2009 15:21:39 +0100
From: Jerome Vuarand <jerome.vuar...@gmail.com>
Reply-To: Lua list <l...@bazar2.conectiva.com.br>
To: Lua <l...@bazar2.conectiva.com.br>
References: <89d273ba0911241013lac6541s14281382f5e44...@mail.gmail.com> <4b0c33c1.6060...@inconcertcc.com> <89d273ba0911250153x3b6f5c0j95da4d4c8f883...@mail.gmail.com> <4b0d1d03.4090...@inconcertcc.com>

2009/11/25 Ignacio Burgueño <ignac...@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.




_______________________________________________
Kepler-Project mailing list
Kepler-Project@lists.luaforge.net
http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project
http://www.keplerproject.org/

Reply via email to