moonbridge

view helloworld.lua @ 127:37532927dba9

Introduced new proto "main" to allow for a main thread
author jbe
date Tue Apr 14 19:30:53 2015 +0200 (2015-04-14)
parents d9cc81641175
children ee98e12427a9
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 = "main" },
10 connect = function()
11 print("Main function executed")
12 end
13 }
15 listen{
16 { proto = "tcp", host = "127.0.0.1", port = 8080 }, -- IPv4
17 { proto = "tcp", host = "::1", port = 8080 }, -- IPv6
18 connect = http.generate_handler(
19 function(request)
20 local function error_response(status)
21 request:send_status(status)
22 request:send_header("Content-Type", "text/html")
23 request:send_data("<html>\n<head><title>", status, "</title></head>\n<body><h1>", status, "</h1></body>\n</html>\n")
24 end
25 if request.method == "GET" or request.method == "HEAD" then
26 if request.path == "" then
27 request:send_status("200 OK")
28 request:send_header("Content-Type", "text/html; charset=UTF-8")
29 request:send_data("<html>\n<head><title>Hello World Application</title></head>\n<body>Hello World!</body>\n</html>\n")
30 else
31 error_response("404 Not Found")
32 end
33 else
34 error_response("405 Method not allowed")
35 end
36 return true
37 end
38 )
39 }

Impressum / About Us