Skip to content

Commit

Permalink
Added server.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jun 5, 2015
1 parent bb30eec commit 1b3542d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ This is the React comment box example from [the React tutorial](http://facebook.

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:

### Lua

```
go get github.com/xyproto/algernon
algernon server.lua
```

### Node

```sh
Expand Down
22 changes: 22 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--
-- 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

0 comments on commit 1b3542d

Please sign in to comment.