lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Feb 12, 2007, at 02:30, jbarciela jbarciela wrote:

I was looking at the alternatives to do web apps in Lua and I have
found that the popular options are basically Apache, lighttpd or
Xavante.

Not sure if it will ever be popular, but here is an example of a pure Lua HTTP tcpserver [1]:

http://dev.alt.textdrive.com/browser/LW/HTTP.lua

Canonical "hello world" example:

----8<----
#!/usr/bin/env lua

local HTTP = require( 'HTTP' )

HTTP[ function() return 'hello world' end ] = '.*'

HTTP()
---->8----

% tcpserver -v -D 0 1080 Hello

% curl http://localhost:1080/
> hello world

Here is an example of a diminutive file server:

local function GetFile( aName )
    local aFile = io.open( aName )

    if aFile then
HTTP.response.header[ 'content-type' ] = 'application/octet-stream'

        return aFile:read( '*a' )
    end
end

HTTP[ GetFile ] = { 'get', '/file/(.*)' }

etc, etc, ...

Cheers,

PA.

[1] http://cr.yp.to/ucspi-tcp/tcpserver.html