moonbridge

view helloworld.lua @ 55:7a385a440fa1

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

Impressum / About Us