From 785b1ad35a691339fa126b6a1aa3325e4a00545a Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 11 Apr 2014 20:37:22 +0100 Subject: [PATCH] Changed requests to trigger a page template from .pages --- lovebird.lua | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lovebird.lua b/lovebird.lua index dfb3914..78981d5 100644 --- a/lovebird.lua +++ b/lovebird.lua @@ -26,6 +26,14 @@ lovebird.maxlines = 200 lovebird.refreshrate = .5 lovebird.pages["index"] = [[ + + @@ -148,7 +156,7 @@ lovebird.pages["index"] = [[ ]] - +lovebird.pages["buffer"] = "" local loadstring = loadstring or load @@ -241,22 +249,16 @@ end function lovebird.onRequest(req, client) - local head = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" - -- Handle request for just the buffer - if req.url:match("buffer") then - return head .. lovebird.buffer + local page = req.parsedurl.path + page = page ~= "" and page or "index" + -- Handle "page not found" + if not lovebird.pages[page] then + return "HTTP/1.1 404\r\nContent-Type: text/html\r\n\r\nBad page" end - -- Handle input - if req.parsedbody.input then - local str = req.parsedbody.input - xpcall(function() assert(loadstring(str))() end, lovebird.onError) - end - -- Generate page - local t = {} - table.insert(t, head) - table.insert(t, lovebird.template(lovebird.pages.index, - { lovebird = lovebird })) - return table.concat(t) + -- Handle existent page + return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" .. + lovebird.template(lovebird.pages[page], + { lovebird = lovebird, req = req }) end