Installing the Software
Three LUA libraries need to be installed: Xavante wsapi Cgilua
Luarocks Install Xavante
Http://keplerproject.github.io/xavante/manual.html#install
Xavante is a Lua HTTP 1.1 Web Server This uses a modular architecture based on URI mapped handlers. Xavante currently offers a file handler, a redirect handler and a WSAPI handler. Those is used for general files, URI remapping and WSAPI applications respectively.
Luarocks Install Wsapi-xavante
Http://keplerproject.github.io/wsapi/index.html
WSAPI is a API that abstracts the Web server from Lua Web applications. By coding against WSAPI your application can run on any of the supported servers and interfaces (currently CGI, FastCGI an D Xavante, on Windows and unix-based systems).
Https://github.com/keplerproject/wsapi
Cgilua
luarocks install cgilua
Https://github.com/keplerproject/cgilua
Cgilua is a tool for creating the dynamic Web pages and manipulating input data from Web Forms. Cgilua allows the separation of logic and data handling from the generation of pages, making it easy to develop web Applic Ations with Lua.
Run the script
Switch to the Cgilua sample directory
[Email protected]:/home/share/cgilua-master/cgilua-master/examples# Lua Xavante_cgilua.lua
[2016-06-22 22:16:50] Xavante started on port (s) 8080
Script content:
Xavante = require "Xavante"
Xavante.filehandler = require "Xavante.filehandler"
Xavante.cgiluahandler = require "Xavante.cgiluahandler"
Xavante.redirecthandler = require "Xavante.redirecthandler"
--Define here where Xavante HTTP documents scripts is located
Local WebDir = "."
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
},
}
--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 (String.Format ("%s Xavante started on port (s)%s",
Date, Table.concat (Ports, ",")))
End
Xavante.start ()
Run Process Analysis
1, Xavante responsible for server startup, and make Cgilua request processing handler Registration
{---cgiluahandler example
Match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$"},
with = Xavante.cgiluahandler.makeHandler (WebDir)
},
2, Xavante.cgiluahandler.makeHandler (WebDir), Handler's structure
-------------------------------------------------------------------------------
--Returns The Cgilua handler
-------------------------------------------------------------------------------
function _m.makehandler (Diskpath, params)
params = setmetatable (params or {}, {__index = {ModName = "Wsapi.sapi",
bootstrap = bootstrap}})
Local Sapi_loader = Common.make_isolated_launcher (params)
Return Xavante.makehandler (Sapi_loader, nil, Diskpath)
End
Where the handler structure relies on the wsapi of Xavante, with the value can be function (req, res)
Local Xavante = require "Wsapi.xavante"---wsapi adaptation specifically for Xavante writing
--Makes a WSAPI handler for a single WSAPI application
function _m.makehandler (App_func, App_prefix, Docroot, App_path, Extra_vars)
return function (req, res)
Return Wsapihandler (req, res, App_func, App_prefix, Docroot, App_path, Extra_vars)
End
End
Construct Cgivars table exists in Wsapi.xavante.
Make_handler entry Wsapi_loader requires WSAPI.SAPI file support
params = setmetatable (params or {}, {__index = {ModName = "Wsapi.sapi",
bootstrap = bootstrap}})
Local Sapi_loader = Common.make_isolated_launcher (params)
This loader loads the Wsapi.sapi file, the file is run by the rings package, i.e. wsapi.sapi–> Cgilua is running in a standalone environment
The existing construct Cgivars table in Wsapi.xavante also passes into the standalone runtime environment.
Wsapi.sapi Call Cgilua directly
Local Cgilua = require "Cgilua"
Cgilua.main ()
Return Res:finish ()
End
Xavante Running Cgilua Process