Skip to content

Commit 1b3542d

Browse files
committed
Added server.lua
1 parent bb30eec commit 1b3542d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ This is the React comment box example from [the React tutorial](http://facebook.
88

99
There are several simple server implementations included. They all serve static files from `public/` and handle requests to `comments.json` to fetch or add data. Start a server with one of the following:
1010

11+
### Lua
12+
13+
```
14+
go get github.com/xyproto/algernon
15+
algernon server.lua
16+
```
17+
1118
### Node
1219

1320
```sh

server.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--
2+
-- For use with Algernon / Lua
3+
--
4+
-- Project page: https://github.com/xyproto/algernon
5+
-- Web page: http://algernon.roboticoverlords.org/
6+
--
7+
8+
-- Set the headers
9+
content("application/javascript")
10+
setheader("Cache-Control", "no-cache")
11+
12+
-- Use a Redis list for the comments
13+
comments = List("comments")
14+
15+
-- Handle requests
16+
if method() == "POST" then
17+
-- Add the form data to the comment list, as JSON
18+
comments:add(JSON(formdata()))
19+
else
20+
-- Combine all the JSON comments to a JSON document
21+
print("["..table.concat(comments:getall(), ",").."]")
22+
end

0 commit comments

Comments
 (0)