Created
December 22, 2010 13:51
-
-
Save ignacio/751528 to your computer and use it in GitHub Desktop.
Route66 example server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "luanode.http" | |
local router = require "route66".new() | |
router:get("/prompt", function(req, res) | |
res:writeHead(200, { ["Content-Type"] = "text/plain"}) | |
res:finish(">:") | |
end) | |
router:get("/hello/(.+)", function(req, res, user) | |
res:writeHead(200, { ["Content-Type"] = "text/plain"}) | |
res:finish("hello " .. user) | |
end) | |
router:post("/send_code", function(req, res) | |
res:writeHead(200, { ["Content-Type"] = "text/plain"}) | |
if req.body == "4 8 15 16 23 42" then | |
res:finish(">:") | |
else | |
res:finish("boom!") | |
end | |
end) | |
local server = luanode.http.createServer(function (self, req, res) | |
console.log("unrouted request will fall through") | |
end) | |
router:bindServer(server) | |
server:listen(8000) | |
console.info("Server listening at http://127.0.0.1:8000/") | |
process:loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment