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@125: { proto = "tcp", host = "127.0.0.1", port = 8080 }, -- IPv4 jbe@125: { proto = "tcp", host = "::1", port = 8080 }, -- IPv6 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@221: request:send_data("\n") jbe@221: request:send_data("", status, "\n") jbe@221: request:send_data("

", status, "

\n") jbe@221: request:send_data("\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@221: request:send_data("\n") jbe@221: request:send_data("Hello World Application\n") jbe@221: request:send_data("

Hello World!

\n") jbe@221: request:send_data("\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: