moonbridge

view helloworld.lua @ 317:f6154dccdab8

Fixed year in LICENSE file
author jbe
date Thu Jul 26 21:43:14 2018 +0200 (4 months ago)
parents db8abd21762c
children
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")
17 request:send_data("<head><title>", status, "</title></head>\n")
18 request:send_data("<body><h1>", status, "</h1></body>\n")
19 request:send_data("</html>\n")
20 end
21 if request.method == "GET" or request.method == "HEAD" then
22 if request.path == "" then
23 request:send_status("200 OK")
24 request:send_header("Content-Type", "text/html; charset=UTF-8")
25 request:send_data("<html>\n")
26 request:send_data("<head><title>Hello World Application</title></head>\n")
27 request:send_data("<body><h1>Hello World!</h1></body>\n")
28 request:send_data("</html>\n")
29 else
30 error_response("404 Not Found")
31 end
32 else
33 error_response("405 Method not allowed")
34 end
35 return true
36 end
37 )
38 }

Impressum / About Us