Note: I believe it was deprecated since Kepler 1.2 -- DanilKutkevich 2010-04-16 13:28 UTC
Example 1
The following code is a simple example of preparing Xavante to virtual host:
-- $SYSCONFDIR/kepler/1.1/xavante/config.lua
require "xavante.filehandler"
require "xavante.redirecthandler"
local function makerules(webDir)
return {
{ -- URI remapping example
match = "^[^%./]*/$",
with = xavante.redirecthandler,
params = {"index.html"}
},
{ -- wsapihandler example
match = {"%.lua$", "%.lua/" },
with = wsapi.xavante.makeGenericHandler (webDir, launcher_params)
},
{ -- wsapihandler example
match = {"%.ws$", "%.ws/" },
with = wsapi.xavante.makeGenericHandler (webDir, launcher_params)
},
{ -- filehandler example
match = ".",
with = xavante.filehandler,
params = { baseDir = webDir }
},
}
end
-- Displays a message in the console with the used ports
xavante.start_message(function (ports)
local date = os.date "[%Y-%m-%d %H:%M:%S]"
print(
("%s Xavante started on port(s) %s"):format(
date,
table.concat(ports, ", ")
)
)
end)
xavante.HTTP {
server = { host = "*", port = 8080 },
defaultHost = {
rules = makerules(XAVANTE_WEB)
},
--virtualhosts = {
-- ["www.client1.com"] = { rules = makerules "/home/client1" },
-- ["www.client2.com"] = { rules = makerules "/home/client2" },
-- ["www.client3.com"] = { rules = makerules "/home/client3" },
--},
}
Example 2
This example adds a CGILua 5.1.3 handler to the rules table:
-- $SYSCONFDIR/kepler/1.1/xavante/config.lua
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)
-- this is necessary to reload CGILua packages and wsapi.sapi since
-- it has way too much dependency on the global environment
package.loaded["cgilua"] = nil
cgilua.SAPI = nil
package.loaded["wsapi.sapi"] = nil
return status, headers, iterator
end
local function makerules(webDir)
return {
{ -- URI remapping example
match = "^[^%./]*/$",
with = xavante.redirecthandler,
params = {"index.lp"},
},
{ -- Lua Pages example
match = "%.lp$",
with = wsapi.xavante.makeHandler(custom_sapi_loader, nil, webdir, webdir),
},
{ -- filehandler example
match = ".",
with = xavante.filehandler,
params = { baseDir = webDir }
},
}
end