annotate helloworld.lua @ 129:df08e63dc44b
Bugfix in close method of moonbridge_io (do not mark as closed before flushing)
author |
jbe |
date |
Tue Apr 14 22:25:32 2015 +0200 (2015-04-14) |
parents |
37532927dba9 |
children |
ee98e12427a9 |
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@127
|
9 { proto = "main" },
|
jbe@127
|
10 connect = function()
|
jbe@127
|
11 print("Main function executed")
|
jbe@127
|
12 end
|
jbe@127
|
13 }
|
jbe@127
|
14
|
jbe@127
|
15 listen{
|
jbe@125
|
16 { proto = "tcp", host = "127.0.0.1", port = 8080 }, -- IPv4
|
jbe@125
|
17 { proto = "tcp", host = "::1", port = 8080 }, -- IPv6
|
jbe@33
|
18 connect = http.generate_handler(
|
jbe@33
|
19 function(request)
|
jbe@33
|
20 local function error_response(status)
|
jbe@33
|
21 request:send_status(status)
|
jbe@33
|
22 request:send_header("Content-Type", "text/html")
|
jbe@33
|
23 request:send_data("<html>\n<head><title>", status, "</title></head>\n<body><h1>", status, "</h1></body>\n</html>\n")
|
jbe@33
|
24 end
|
jbe@33
|
25 if request.method == "GET" or request.method == "HEAD" then
|
jbe@33
|
26 if request.path == "" then
|
jbe@33
|
27 request:send_status("200 OK")
|
jbe@33
|
28 request:send_header("Content-Type", "text/html; charset=UTF-8")
|
jbe@33
|
29 request:send_data("<html>\n<head><title>Hello World Application</title></head>\n<body>Hello World!</body>\n</html>\n")
|
jbe@33
|
30 else
|
jbe@33
|
31 error_response("404 Not Found")
|
jbe@33
|
32 end
|
jbe@33
|
33 else
|
jbe@33
|
34 error_response("405 Method not allowed")
|
jbe@33
|
35 end
|
jbe@33
|
36 return true
|
jbe@33
|
37 end
|
jbe@33
|
38 )
|
jbe@33
|
39 }
|
jbe@33
|
40
|