annotate helloworld.lua @ 216:52e787f12707
Added $(UTIL_FLAGS) to moonbridge_io.so in Makefile
author |
jbe |
date |
Mon Jun 22 22:49:31 2015 +0200 (2015-06-22) |
parents |
ee98e12427a9 |
children |
db8abd21762c |
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@125
|
9 { proto = "tcp", host = "127.0.0.1", port = 8080 }, -- IPv4
|
jbe@125
|
10 { proto = "tcp", host = "::1", port = 8080 }, -- IPv6
|
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
|