moonbridge

annotate helloworld.lua @ 123:20e0d4f51381

Updated chat example
author bsw
date Sat Apr 11 00:20:33 2015 +0200 (2015-04-11)
parents 59f485dc48ea
children d9cc81641175
rev   line source
jbe@33 1 -- minimal example application for Moonbridge
jbe@33 2 -- invoke with ./moonbridge helloworld.lua
jbe@33 3 --
jbe@33 4 -- see example_application.lua for a more elaborated example
jbe@33 5
jbe@33 6 local http = require "moonbridge_http"
jbe@33 7
jbe@33 8 listen{
jbe@33 9 { proto = "tcp4", port = 8080, localhost = true },
jbe@33 10 { proto = "tcp6", port = 8080, localhost = true },
jbe@33 11 connect = http.generate_handler(
jbe@33 12 function(request)
jbe@33 13 local function error_response(status)
jbe@33 14 request:send_status(status)
jbe@33 15 request:send_header("Content-Type", "text/html")
jbe@33 16 request:send_data("<html>\n<head><title>", status, "</title></head>\n<body><h1>", status, "</h1></body>\n</html>\n")
jbe@33 17 end
jbe@33 18 if request.method == "GET" or request.method == "HEAD" then
jbe@33 19 if request.path == "" then
jbe@33 20 request:send_status("200 OK")
jbe@33 21 request:send_header("Content-Type", "text/html; charset=UTF-8")
jbe@33 22 request:send_data("<html>\n<head><title>Hello World Application</title></head>\n<body>Hello World!</body>\n</html>\n")
jbe@33 23 else
jbe@33 24 error_response("404 Not Found")
jbe@33 25 end
jbe@33 26 else
jbe@33 27 error_response("405 Method not allowed")
jbe@33 28 end
jbe@33 29 return true
jbe@33 30 end
jbe@33 31 )
jbe@33 32 }
jbe@33 33

Impressum / About Us