Changed requests to trigger a page template from .pages

This commit is contained in:
rxi
2014-04-11 20:37:22 +01:00
parent e80439e883
commit 785b1ad35a

View File

@@ -26,6 +26,14 @@ lovebird.maxlines = 200
lovebird.refreshrate = .5 lovebird.refreshrate = .5
lovebird.pages["index"] = [[ lovebird.pages["index"] = [[
<?lua
-- Handle console input
if req.parsedbody.input then
local str = req.parsedbody.input
xpcall(function() assert(loadstring(str))() end, lovebird.onError)
end
?>
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
@@ -148,7 +156,7 @@ lovebird.pages["index"] = [[
</html> </html>
]] ]]
lovebird.pages["buffer"] = "<?lua echo(lovebird.buffer) ?>"
local loadstring = loadstring or load local loadstring = loadstring or load
@@ -241,22 +249,16 @@ end
function lovebird.onRequest(req, client) function lovebird.onRequest(req, client)
local head = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" local page = req.parsedurl.path
-- Handle request for just the buffer page = page ~= "" and page or "index"
if req.url:match("buffer") then -- Handle "page not found"
return head .. lovebird.buffer if not lovebird.pages[page] then
return "HTTP/1.1 404\r\nContent-Type: text/html\r\n\r\nBad page"
end end
-- Handle input -- Handle existent page
if req.parsedbody.input then return "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" ..
local str = req.parsedbody.input lovebird.template(lovebird.pages[page],
xpcall(function() assert(loadstring(str))() end, lovebird.onError) { lovebird = lovebird, req = req })
end
-- Generate page
local t = {}
table.insert(t, head)
table.insert(t, lovebird.template(lovebird.pages.index,
{ lovebird = lovebird }))
return table.concat(t)
end end