1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
Configuration with wsapi
========================
Here we give a simple example of apache2 configuration, where many lua
scripts [2] or lua pages[3] are executed in response to URL of the form:
http://server/app/script.lua
http://server/app/page.lp
The following rather standard apache2 configuration snippet allows
scripts in /www to be executed as CGIs. Note that the app script will
be placed in DocumentRoot.
<VirtualHost server>
DocumentRoot /www/
<Location />
SetHandler cgi-script
Options +ExecCGI
</Location>
</VirtualHost>
Then /www/app has to be something like the following lua snippet:
#!/usr/bin/lua5.1
require "wsapi.sapi"
require "wsapi.cgi"
CGILUA_CONF="/non-existent/"
wsapi.cgi.run(wsapi.sapi.run)
The CGILUA_CONF can be se to a directory path that contains a file named
config.lua. For example you can define special handlers associated to
particular file extensions (there are default ones for .lp and .lua files).
All configuration options are described in [4].
The following sample Lua page /www/app/page.lp prints all the parameters
eventually passed to the page (e.g. page.lp?foo=bar).
<html> <body> <dl>
<? t = {}
cgilua.urlcode.parsequery(cgilua.servervariable("QUERY_STRING"),t)
for key,val in pairs(t) do ?>
<dt><? =key ?></dt>
<dd><? =val ?></dd>
<? end ?>
</dl> </body> </html>
Lua scrips are equipotent to Lua pages, but are better suited for implementing
tasks rather then pages, since it is not allowed to mix HTML and Lua code. A
sample Lua script follows:
cgilua.htmlheader()
cgilua.print("<html><body>test</body></html>")
Reference
=========
[2]: file:///usr/share/doc/liblua5.1-cgi-dev/doc/us/manual.html#scripts
[3]: file:///usr/share/doc/liblua5.1-cgi-dev/doc/us/manual.html#templates
[4]: file:///usr/share/doc/liblua5.1-cgi-dev/doc/us/manual.html#config
|