Skip to content

Commit 89fd834

Browse files
committed
Merge pull request reactjs#55 from xyproto/lua
Added server.lua
2 parents 78c36e3 + 83202d3 commit 89fd834

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
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
25+
26+
end)
27+
28+
servedir("/", "public")

0 commit comments

Comments
 (0)