Skip to content

Instantly share code, notes, and snippets.

@ignacio
Created December 22, 2010 13:51
Show Gist options
  • Save ignacio/751528 to your computer and use it in GitHub Desktop.
Save ignacio/751528 to your computer and use it in GitHub Desktop.
Route66 example server.
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