2 local httpserver = require "net.httpserver";
5 local t_concat = table.concat;
7 local http_base = "www_files";
9 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
11 local http_path = { http_base };
12 local function handle_request(method, body, request)
13 local path = request.url.path:gsub("%.%.%/", ""):gsub("^/[^/]+", "");
15 local f, err = open(t_concat(http_path), "r");
16 if not f then return response_404; end
17 local data = f:read("*a");
22 local ports = config.get(module.host, "core", "http_ports") or { 5280 };
23 for _, options in ipairs(ports) do
24 local port, base, ssl, interface = 5280, "files", false, nil;
25 if type(options) == "number" then
27 elseif type(options) == "table" then
28 port, base, ssl, interface = options.port or 5280, options.path or "files", options.ssl or false, options.interface;
29 elseif type(options) == "string" then
32 httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl }