Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
28 changes: 28 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--
-- For use with Algernon / Lua
--
-- Project page: https://github.com/xyproto/algernon
-- Web page: http://algernon.roboticoverlords.org/
--

handle("/comments.json", function()

-- 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

end)

servedir("/", "public")