jbe@33: -- minimal example application for Moonbridge jbe@33: -- invoke with ./moonbridge helloworld.lua jbe@33: -- jbe@33: -- see example_application.lua for a more elaborated example jbe@33: jbe@33: local http = require "moonbridge_http" jbe@33: jbe@33: listen{ jbe@33: { proto = "tcp4", port = 8080, localhost = true }, jbe@33: { proto = "tcp6", port = 8080, localhost = true }, jbe@33: connect = http.generate_handler( jbe@33: function(request) jbe@33: local function error_response(status) jbe@33: request:send_status(status) jbe@33: request:send_header("Content-Type", "text/html") jbe@33: request:send_data("\n", status, "\n

", status, "

\n\n") jbe@33: end jbe@33: if request.method == "GET" or request.method == "HEAD" then jbe@33: if request.path == "" then jbe@33: request:send_status("200 OK") jbe@33: request:send_header("Content-Type", "text/html; charset=UTF-8") jbe@33: request:send_data("\nHello World Application\nHello World!\n\n") jbe@33: else jbe@33: error_response("404 Not Found") jbe@33: end jbe@33: else jbe@33: error_response("405 Method not allowed") jbe@33: end jbe@33: return true jbe@33: end jbe@33: ) jbe@33: } jbe@33: