moonbridge
diff helloworld.lua @ 33:59f485dc48ea
Removed method request:send_text_status_response(...); Added helloworld.lua
author | jbe |
---|---|
date | Tue Feb 17 13:15:08 2015 +0100 (2015-02-17) |
parents | |
children | d9cc81641175 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/helloworld.lua Tue Feb 17 13:15:08 2015 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +-- minimal example application for Moonbridge 1.5 +-- invoke with ./moonbridge helloworld.lua 1.6 +-- 1.7 +-- see example_application.lua for a more elaborated example 1.8 + 1.9 +local http = require "moonbridge_http" 1.10 + 1.11 +listen{ 1.12 + { proto = "tcp4", port = 8080, localhost = true }, 1.13 + { proto = "tcp6", port = 8080, localhost = true }, 1.14 + connect = http.generate_handler( 1.15 + function(request) 1.16 + local function error_response(status) 1.17 + request:send_status(status) 1.18 + request:send_header("Content-Type", "text/html") 1.19 + request:send_data("<html>\n<head><title>", status, "</title></head>\n<body><h1>", status, "</h1></body>\n</html>\n") 1.20 + end 1.21 + if request.method == "GET" or request.method == "HEAD" then 1.22 + if request.path == "" then 1.23 + request:send_status("200 OK") 1.24 + request:send_header("Content-Type", "text/html; charset=UTF-8") 1.25 + request:send_data("<html>\n<head><title>Hello World Application</title></head>\n<body>Hello World!</body>\n</html>\n") 1.26 + else 1.27 + error_response("404 Not Found") 1.28 + end 1.29 + else 1.30 + error_response("405 Method not allowed") 1.31 + end 1.32 + return true 1.33 + end 1.34 + ) 1.35 +} 1.36 +