Installing
Xavante follows the
package model
for Lua 5.1, therefore it should be "installed" in your package.path
.
This will add Xavante as a module to your system so you can require
it as part of your application. If you want to use Xavante as a standalone web server please check the Kepler distribution. Kepler offers Xavante launchers for Unix and Windows both on the command line and as a Windows Tray application.
Configuring
After the Xavante module is loaded, it needs to be configured before being able to serve requests. If you are using Kepler this is done in the KEPLER_CONF/xavante/config.lua
file, but if you are using Xavante as a module you need to register the handlers using the
xavante.HTTP
constructor.
xavante.HTTP
defines virtualhosts for each site
that will be served. Each virtualhost can define a set of rules
for it.
Each rule matches a URL Lua pattern with a handler.
Xavante currently offers a file handler,
a redirect handler and
a CGILua handler for general files, URL
remapping and CGILua scripts respectively.
A typical use would be (assuming the Xavante module is already loaded):
require "xavante.filehandler" require "xavante.cgiluahandler" require "xavante.redirecthandler" -- Define here where Xavante HTTP documents scripts are located local webDir = XAVANTE_WEB local simplerules = { { -- URI remapping example match = "^[^%./]*/$", with = xavante.redirecthandler, params = {"index.lp"} }, { -- cgiluahandler example match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" }, with = xavante.cgiluahandler.makeHandler (webDir) }, { -- filehandler example match = ".", with = xavante.filehandler, params = {baseDir = webDir} }, } xavante.HTTP{ server = {host = "*", port = 8080}, defaultHost = { rules = simplerules }, }
Note the use of webDir
both to set the base directory
for the file handler and for the CGILua scripts. These paths should contain the
desired directories in your structure.
To use virtual hosts with Xavante, the call to xavante.HTTP
would be changed to something like
xavante.HTTP{ server = {host = "*", port = 8080}, defaultHost = {}, virtualhosts = { ["www.sitename.com"] = simplerules } }
Running
If you are using Xavante as part of the Kepler distribution, please refer to the Kepler documentation for details on how to execute Xavante from the command line or the Windows Tray bar.
If you are using Xavante as a module, then to start it you need to call
xavante.start([checkfunction[, timeout]])
passing an optional
checking function and connection timeout value. The checking function, if
present, will be called periodically to check if Xavante should continue to
run. This function can be also used for maintenance tasks or as a callback to
your application.