#!/usr/bin/env lua
local fcgi = require"fcgi"
local etlua = require"etlua"
apps = {
yqtemplate = require"yqtemplate"
}
local template = etlua.compile[[
Annwan's CGI scripts
<% if app and app ~= "" then %>
No such application: <%= app -%>
<% end %>
Available Applications
<% for name, appdata in pairs(apps) do %>
- ><%=name -%>: <%= appdata.desc -%>
<% end %>
]]
while fcgi.accept() do
app = fcgi.getenv("DOCUMENT_URI"):sub(6)
appfn = apps[app]
if appfn then
appfn.run(fcgi)
else
fcgi.print"Content-Type: text/html; charset=utf-8\r\n\r\n"
fcgi.print(template{
app = app,
apps = apps
})
end
end