Skip to content

Instantly share code, notes, and snippets.

@ignacio
Created December 22, 2010 13:51

Revisions

  1. ignacio renamed this gist Dec 22, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ignacio renamed this gist Dec 22, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. ignacio created this gist Dec 22, 2010.
    33 changes: 33 additions & 0 deletions gistfile1.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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()