From 7fad9fd4f641b46c0932549fb9def5631df5f729 Mon Sep 17 00:00:00 2001 From: Annwan Date: Sun, 11 Aug 2024 22:34:34 +0200 Subject: [PATCH] [Dispatch] added application descriptions --- main.lua | 16 +++++++++++----- yqtemplate.lua | 11 +++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main.lua b/main.lua index 7fe47de..27107ae 100755 --- a/main.lua +++ b/main.lua @@ -1,15 +1,21 @@ #!/usr/bin/env lua local fcgi = require"fcgi" -local app_yqtemplate = require"yqtemplate" - +apps = { + yqtemplate = require"yqtemplate" +} while fcgi.accept() do app = fcgi.getenv("DOCUMENT_URI"):sub(6) - if app == "yqtemplate" then - app_yqtemplate(fcgi) + appfn = apps[app] + if appfn then + appfn.run(fcgi) else fcgi.print"Content-Type: text/plain; charset=utf-8\r\n\r\n" - fcgi.print("Unknown CGI application: `" .. app .. "'\n") + fcgi.print("No such application application: `" .. app .. "'\n") + fcgi.print("Available applications:\n") + for n, x in pairs(apps) do + fcgi.print(" - " .. n .. ": " .. x.desc .. "\n") + end end end diff --git a/yqtemplate.lua b/yqtemplate.lua index 11f3d56..b228aae 100644 --- a/yqtemplate.lua +++ b/yqtemplate.lua @@ -1,4 +1,7 @@ -return function(fcgi) - fcgi.print("Content-Type: text/plain; charset=utf-8\r\n\r\n") - fcgi.print("Hello from application `YQTemplate'") -end +return { + desc = "Creates Yokoka’s quest-style personal status page", + run = function(fcgi) + fcgi.print("Content-Type: text/plain; charset=utf-8\r\n\r\n") + fcgi.print("Hello from application `YQTemplate'") + end +}