--
-- For use with Algernon / Lua
-- 
-- Project page: https://github.com/xyproto/algernon
-- Web page: http://algernon.roboticoverlords.org/
--

-- Set the headers
content("application/javascript")
setheader("Cache-Control", "no-cache")

-- Use a Redis list for the comments
comments = List("comments")

-- Handle requests
if method() == "POST" then
  -- Add the form data to the comment list, as JSON
  comments:add(JSON(formdata()))
else
  -- Combine all the JSON comments to a JSON document
  print("["..table.concat(comments:getall(), ",").."]")
end

--
-- For use with Algernon / Lua
-- 
-- Project page: https://github.com/xyproto/algernon
-- Web page: http://algernon.roboticoverlords.org/
--

-- Set the headers
content("application/javascript")
setheader("Cache-Control", "no-cache")

-- Use a JSON file for the comments
comments = JFile("comments.json")

-- Handle requests
if method() == "POST" then
  -- Add the form data table to the JSON document
  comments:add(ToJSON(formdata()))
else
  -- Return the contents of the JSON file
  print(tostring(comments))
end

Use the JSON document for storing comments
Use the JSON document for storing comments
