Skip to content

Commit 83202d3

Browse files
committed
Made the Lua sample work like the other samples
1 parent 5ed1252 commit 83202d3

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

server.lua

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
--
22
-- For use with Algernon / Lua
3-
--
3+
--
44
-- Project page: https://github.com/xyproto/algernon
55
-- Web page: http://algernon.roboticoverlords.org/
66
--
77

8-
-- Set the headers
9-
content("application/javascript")
10-
setheader("Cache-Control", "no-cache")
8+
handle("/comments.json", function()
9+
10+
-- Set the headers
11+
content("application/javascript")
12+
setheader("Cache-Control", "no-cache")
13+
14+
-- Use a JSON file for the comments
15+
comments = JFile("comments.json")
16+
17+
-- Handle requests
18+
if method() == "POST" then
19+
-- Add the form data table to the JSON document
20+
comments:add(ToJSON(formdata()))
21+
else
22+
-- Return the contents of the JSON file
23+
print(tostring(comments))
24+
end
1125

12-
-- Use a JSON file for the comments
13-
comments = JFile("comments.json")
26+
end)
1427

15-
-- Handle requests
16-
if method() == "POST" then
17-
-- Add the form data table to the JSON document
18-
comments:add(ToJSON(formdata()))
19-
else
20-
-- Return the contents of the JSON file
21-
print(tostring(comments))
22-
end
28+
servedir("/", "public")

0 commit comments

Comments
 (0)