Xavante
A Lua Web Server with WSAPI support

Installing

You can install Xavante using LuaRocks:

luarocks install xavante

The "xavante" package installs Xavante as a library. To run Xavante as an application please install WSAPI:

luarocks install wsapi-xavante

Configuring

After the Xavante module is loaded, it needs to be configured before being able to serve requests. 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:

local hfile = require "xavante.filehandler"
local hcgi = require "xavante.cgiluahandler"
local hredir = require "xavante.redirecthandler"

local xavante = require "xavante"
  
-- Define here where Xavante HTTP documents scripts are located
local webDir = XAVANTE_WEB

local simplerules = {

    { -- URI remapping example
      match = "^[^%./]*/$",
      with = hredir,
      params = {"index.lp"}
    }, 

    { -- cgiluahandler example
      match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" },
      with = hcgi.makeHandler (webDir)
    },
    
    { -- filehandler example
      match = ".",
      with = hfile,
      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 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.

Valid XHTML 1.0!

$Id: manual.html,v 1.46 2008/05/23 20:18:58 carregal Exp $