moonbridge

view helloworld.lua @ 133:891cdc4b43eb

Revised flushing behavior of write_nb(...) again
author jbe
date Thu Apr 16 20:48:11 2015 +0200 (2015-04-16)
parents ee98e12427a9
children db8abd21762c
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 = "tcp", host = "127.0.0.1", port = 8080 }, -- IPv4
10 { proto = "tcp", host = "::1", port = 8080 }, -- IPv6
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